PreviewKeyDown for Windows Store App ListBox [英] PreviewKeyDown for Windows Store App ListBox

查看:21
本文介绍了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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆