开发者

WPF ComboBox & IsTabStop behavior

I have a problem with ComboBox control on WPF.

I tried to set IsTabStop property to control but it don't works as expected.

If ComboBox is not editable, IsTabStop works correctly, but if ComboBox is editable it always take the focus from keyboard navigation. IsTabStop = false has no effect!

Furthermore, when ComboBox is editable and IsTabStop is true, keyboard navigation to previous control is "locked"..."Shift+Tab" doesn't works!

Is this a WPF bug? Is there any workaround?

I'm using .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.

Also DatePicker seems have same issue.


A bit late, but I was looking this exact same issue up the other day. I found that KeyboardNavigation.TabNavigation="None" solves the problem.


yeah seems to be the issue with ComboBox, somebody raised it with microsoft:

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:

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

Change myCbo for your combobox name.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜