Text box key up event in WPF
How to 开发者_如何转开发use ICommand in key up event of a text box using MVVM architecture?
You have a readymade helper class to handle event to command behaviour in MVVM Light Toolkit.
You can use InvokeDataCommand trigger from Expression Blend Samples:
<TextBox>
<i:Interaction.Triggers>
<i:EventTrigger EventName="KeyUp">
<si:InvokeDataCommand Command="{Binding MyCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBox>
MVVM doesn't forbid you to write code-behind - this is a common misunderstanding. You can listen to the KeyUp event of the TextBox in the code-behind file of the View and delegate the call to the ViewModel object.
How this works is shown in the ViewModel sample application of the WPF Application Framework (WAF).
精彩评论