PreviewKeyDown为Windows Store应用列表框 [英] PreviewKeyDown for Windows Store App ListBox

查看:142
本文介绍了PreviewKeyDown为Windows Store应用列表框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个相当于 PreviewKeyDown 的Windows Store应用?它不可。



我有完全一样的问题的这里描述:




我与它上面的一个文本框的列表框。我想使用箭头键从列表框中的文本框进行导航。其意图是,如果选择在ListBox中的第一个项目,用户按键后,文本框将获得焦点。



解决方案

嗯,很棘手。处理关键事件是不是超明显。这里是你想要什么:

 公开的MainPage()
{
this.InitializeComponent();
Window.Current.CoreWindow.Dispatcher.AcceleratorKeyActivated + =(S,参数)=>
{
如果((args.EventType == CoreAcceleratorKeyEventType.SystemKeyDown
|| args.EventType == CoreAcceleratorKeyEventType.KeyDown)
和;及(args.VirtualKey == VirtualKey .UP))
{
MoveUp上();
}
,否则如果((args.EventType == CoreAcceleratorKeyEventType.SystemKeyDown
|| args.EventType == CoreAcceleratorKeyEventType.KeyDown)
和;及(args.VirtualKey == VirtualKey.Down))
{
下移();
}
};
}

私人无效MoveUp上()
{
//这部分是由你
抛出新NotImplementedException();
}

私人无效下移()
{
//这部分是由你
抛出新NotImplementedException();
}



祝你好运!


Is there an equivalent to the PreviewKeyDown for a Windows Store App? It isn't available.

I have exactly the same problem as described here:

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();
}

Best of luck!

这篇关于PreviewKeyDown为Windows Store应用列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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