How to pass multiple parameters and EventArgs properties when using EventToCommand in MVVM-Light toolkit
I am using MVVM Light toolkit for my WPF application and 开发者_运维技巧I would like to know if its possible, when using EventToCommand, to pass multiple parameters to RelayCommand and Is it possible to pass properties of EventArgs instead of passing the whole EventArgs ?
Regards, Nabeel
what if the scenario is
<i:Interaction.Triggers>
<i:EventTrigger EventName="KeyDown">
<cmd:EventToCommand Command="{Binding SearchKey}" PassEventArgsToCommand="True"
CommandParameter="{Binding Text, ElementName=TextSearchCashDrawer}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
what is on enter key press i need to read the text from the textbox and perform search.
SearchKey=new RelayCommand<KeyEventArgs>(e=>
{
if(e.PlatformKeyCode==13) //enter key
{
}
});
using this I can filter which key has been pressed but how to get that parameter if enter key is pressed in this mvvmlight.
If all you want to do is capture the enter key press, you can create a KeyBinding via InputBinding. The following example in XAML would capture the Enter key press in the TextBox and the Command, FindCommand in this case, would handle it in your ViewModel.
<TextBox Width="80">
<TextBox.InputBindings>
<KeyBinding Key="Enter" Command="{Binding FindCommand}" />
</TextBox.InputBindings>
</TextBox>
Worked for me!
精彩评论