It is very easy to bind Button
s in WPF apps to Command
s in a VIEWMODEL
class. I'd like to achieve a similar binding for a TextBox
.
I have a TextBox
and I need to bind it to a Command
that fires up when I hit Enter while the TextBox
is focused. Currently, I'm using the following handler for the KeyUp
event, but it looks ugly...
and I can't put it in my VIEWMODEL
class.
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!");
}
}
Is there a better way to do this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…