PreviewKeyDown for Windows Store App ListBox(PreviewKeyDown for Windows Store App ListBox)
问题描述
对于 Windows 应用商店应用,是否有与 PreviewKeyDown
等效的方法?不可用.
Is there an equivalent to the PreviewKeyDown
for a Windows Store App? It isn't available.
我的问题与 此处描述:
我有一个 ListBox,上面有一个 TextBox.我想使用箭头键从 ListBox 导航到 TextBox.目的是如果 ListBox 中的第一项被选中,并且用户向上键,TextBox 将获得焦点.
I have a ListBox with a TextBox above it. I would like to use the arrow keys to navigate from the ListBox to the TextBox. The intention is that if the first item in the ListBox is selected, and the user keys up, the TextBox will get focus.
推荐答案
啊,棘手.处理关键事件并不是很明显.这就是你想要的:
Ah, tricky. Handling key events isn't super-obvious. Here's what you want:
public MainPage()
{
this.InitializeComponent();
Window.Current.CoreWindow.Dispatcher.AcceleratorKeyActivated += (s, args) =>
{
if ((args.EventType == CoreAcceleratorKeyEventType.SystemKeyDown
|| args.EventType == CoreAcceleratorKeyEventType.KeyDown)
&& (args.VirtualKey == VirtualKey.Up))
{
MoveUp();
}
else if ((args.EventType == CoreAcceleratorKeyEventType.SystemKeyDown
|| args.EventType == CoreAcceleratorKeyEventType.KeyDown)
&& (args.VirtualKey == VirtualKey.Down))
{
MoveDown();
}
};
}
private void MoveUp()
{
// this part is up to you
throw new NotImplementedException();
}
private void MoveDown()
{
// this part is up to you
throw new NotImplementedException();
}
祝你好运!
这篇关于PreviewKeyDown for Windows Store App ListBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PreviewKeyDown for Windows Store App ListBox


- MoreLinq maxBy vs LINQ max + where 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 输入按键事件处理程序 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 如何用自己压缩一个 IEnumerable 2022-01-01