将WPF应用程序中的Button
个绑定到VIEWMODEL
类中的Command
个非常容易.我想为TextBox
实现类似的绑定.
我有一个TextBox
,我需要将它绑定到Command
,当我在TextBox
处于焦点时按enter时会触发Command
.目前,我正在为KeyUp
事件使用以下处理程序,但它看起来很难看…
我不能把它放在我的VIEWMODEL
班.
private void TextBox_KeyUp(object sender, KeyEventArgs e)
{
if (e.Key == System.Windows.Input.Key.Enter)
{
// your event handler here
e.Handled = true;
MessageBox.Show("Enter Key is pressed!");
}
}
有更好的方法吗?