[英]UWP problems in detecting the “Enter” key pressed
当我在键盘上按Enter键时,我试图在我的应用程序中运行某些功能,但是这样做有问题。
KeyboardControl
在我的文本框的KeyDown
中。
Key.Enter
无法识别为函数,我也不知道该怎么办。
// When a key is pressed on the keyboard
private void KeyboardControl(object sender, KeyEventArgs e)
{
if (e.KeyStatus == Key.Enter)
{
PercentCalc();
PercentageValue.Text = Convert.ToString(result, new CultureInfo("en-US")) + "%";
}
}
像这样将KeyDown事件附加到您的TexBox :
<TextBox KeyDown="Box_KeyDown" />
在后端keydown事件中,检查按下的键是否为Enter ,然后在满足条件的情况下执行代码。
private async void Box_KeyDown(object sender, Windows.UI.Xaml.Input.KeyRoutedEventArgs e)
{
if (e.Key == Windows.System.VirtualKey.Enter)
{//execute code here
PercentCalc();
PercentageValue.Text = Convert.ToString(result, new CultureInfo("en-US")) + "%";
}
}
您试图检查用例中不需要的KeyStatus ,而是应该检查按下了哪个键。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.