我可以使用箭头键而不是tab来导航进出wpf组合框? [英] Can I navigate into and out of a wpf combo box using arrow keys instead of tab?

查看:255
本文介绍了我可以使用箭头键而不是tab来导航进出wpf组合框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有wpf UserControl包含一个组合框和一个文本框在一行。目前,在组件之间移动的唯一方法是在它们之间的tab,但我也希望能够使用向左和向右箭头键从组合框切换到文本框。

I have wpf UserControl containing a combobox and a textbox in a row. Currently the only way to move between the components is to tab between them, but I would like to also be able to switch from the combobox to the textbox using the left and right arrow keys.

在keyup事件上敲击事件处理程序并不容易。

It is not as easy as just slapping an eventhandler on the keyup event.

void ComboKeyUp( object sender, KeyEventArgs e )
{
    if( e.Key == Key.Right)
    {
        e.Handled = true;
        textbox.Focus();
    }
}

...因为组合将更改值,事件被报告为已处理。

...because the combo will change value despite the event being reported as handled.

有没有办法做到这一点,不会同时打破组合框中的项目的上/下选择?

Is there a way to do this that doesn't simultaneously break the up/down selection of items in the combo box?

推荐答案

原来有一个getcha,你已经订阅了KeyDown事件。

It turns out there is a gotcha, you have subscribe to the KeyDown event instead.

这篇关于我可以使用箭头键而不是tab来导航进出wpf组合框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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