tags:

views:

44

answers:

3

How to use ICommand in key up event of a text box using MVVM architecture?

A: 

You have a readymade helper class to handle event to command behaviour in MVVM Light Toolkit.

Veer
Could you please explain and tell me how to get the dll for that toolkit?
@gowri-ganapathy: check this link for the installation procedure: http://www.galasoft.ch/mvvm/installing/manually/
Veer
+1  A: 

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>
PL
A: 

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

jbe