开发者

Text box key up event in WPF

开发者 https://www.devze.com 2023-01-04 19:18 出处:网络
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 Invo

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).

0

精彩评论

暂无评论...
验证码 换一张
取 消