[英]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.