简体   繁体   English

WPF ComboBox & IsTabStop 行为

[英]WPF ComboBox & IsTabStop behavior

I have a problem with ComboBox control on WPF.我对 WPF 上的ComboBox控制有问题。

I tried to set IsTabStop property to control but it don't works as expected.我试图将IsTabStop属性设置为控制,但它没有按预期工作。

If ComboBox is not editable, IsTabStop works correctly, but if ComboBox is editable it always take the focus from keyboard navigation.如果ComboBox不可编辑, IsTabStop工作正常,但如果ComboBox可编辑,则它始终从键盘导航中获取焦点。 IsTabStop = false has no effect! IsTabStop = false没有效果!

Furthermore, when ComboBox is editable and IsTabStop is true, keyboard navigation to previous control is "locked"..."Shift+Tab" doesn't works!此外,当ComboBox是可编辑的并且IsTabStop为真时,键盘导航到上一个控件被“锁定”...“Shift+Tab”不起作用!

Is this a WPF bug?这是 WPF 错误吗? Is there any workaround?有什么解决方法吗?

I'm using.Net 4.0.我正在使用.Net 4.0。

This is an example...这是一个例子...

<Window
   x:Class="MainWindow"
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   Title="MainWindow"
   Height="250"
   Width="600">

   <StackPanel
     Orientation="Horizontal"
     VerticalAlignment="Center">
     <TextBox
        Width="50"
        IsTabStop="True">
     </TextBox>
    <ComboBox
        Name="cmb1"
        Margin="10,0,0,0"
        Width="50"
        IsEditable="True"
        IsTabStop="False">
    </ComboBox>
    <DatePicker
        Name="dp1"
        Margin="10,0,0,0"
        Width="50"
        IsTabStop="True">
    </DatePicker>
    <TextBox
        Margin="10,0,0,0"
        Width="50"
        IsTabStop="False">
    </TextBox>
    <ComboBox
        Name="cmb2"
        Margin="10,0,0,0"
        Width="50"
        IsTabStop="False">
    </ComboBox>
    <ComboBox
        Name="cmb3"
        Margin="10,0,0,0"
        Width="50"
        IsEditable="True"
        IsTabStop="True">
    </ComboBox>

   </StackPanel>
 </Window>

try to navigate with tab from first textbox to last combobox..."cmb1" take focus also with IsTabStop=False, "cmb2" is ok bacause it's not editable, on "cmb3" it's not possible return to previous control with Shift+Tab.尝试使用选项卡从第一个文本框导航到最后一个 combobox..."cmb1" 也使用 IsTabStop=False 进行聚焦,"cmb2" 没问题,因为它不可编辑,在 "cmb3" 上无法使用 Shift+Tab 返回上一个控件.

Also DatePicker seems have same issue. DatePicker 似乎也有同样的问题。

A bit late, but I was looking this exact same issue up the other day.有点晚了,但前几天我正在寻找完全相同的问题。 I found that KeyboardNavigation.TabNavigation="None" solves the problem.我发现KeyboardNavigation.TabNavigation="None"解决了这个问题。

yeah seems to be the issue with ComboBox, somebody raised it with microsoft:是的,似乎是 ComboBox 的问题,有人向微软提出:

Have a look here . 看看这里 It seems to have a workaround.它似乎有一个解决方法。

Here is a workaround.这是一种解决方法。 In the Loaded event of your window/control place this code:在窗口/控件的 Loaded 事件中放置以下代码:

var textBox = myCbo.Template.FindName("PART_EditableTextBox", myCbo) as TextBox;
if (textBox != null)
   textBox.IsTabStop = myCbo.IsTabStop;

Change myCbo for your combobox name.将 myCbo 更改为您的 combobox 名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM