【发布时间】:2012-09-12 13:25:08
【问题描述】:
我正在使用 C# 和 XAML,在 Windows 8 上开发 Metro 风格的应用程序。我想在 keyup 事件上捕获 enter 按钮,但它适用于除 enter 和空格键之外的所有键盘按钮。我的代码
XAML
<Button x:Name="btnName" KeyUp="KeyboardKey_Pressed">
</Button>
C#源代码
public void KeyboardKey_Pressed(object sender, KeyRoutedEventArgs e)
{
if (e.Key == Windows.System.VirtualKey.Enter)
......
}
我知道如果我使用 TextBox 而不是 Button,它会起作用,但我想使用一个按钮。我该怎么做?
【问题讨论】:
-
在 TextBox 上使用 Button 不是打破常规 UI 约定吗?
标签: .net xaml windows-8 windows-runtime