This .Net 4 only solution binds the DelegateCommand to the Command property of a KeyBinding.
...
KeyReturnCommand = new DelegateCommand(ReturnKeyPressed);
...
public DelegateCommandKeyReturnCommand { get; set; }
private void ReturnKeyPressed(string text)
{
MessageBox.Show(text);
}
<TextBox x:Name="SearchText" Width="100" Height="25">
<TextBox.InputBindings>
<KeyBinding
Command="{Binding KeyReturnCommand}"
CommandParameter="{Binding ElementName=SearchText, Path=Text}"
Key="Enter"/>
</TextBox.InputBindings>
</TextBox>
No comments:
Post a Comment