Button
将WPF 应用程序中Command
的 s绑定到类中的 s 非常容易VIEWMODEL
。我想为 a 实现类似的绑定TextBox
。
我有一个TextBox
,我需要将它绑定到当我在聚焦时击中时Command
会触发的 a。目前,我正在为该事件使用以下处理程序,但它看起来很难看......而且我不能把它放在我的课堂上。EnterTextBox
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!");
}
}
有一个更好的方法吗?