PreviewKeyDown for Windows Store App ListBox

PreviewKeyDown for Windows Store App ListBox(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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)