Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF ComboBox & IsTabStop behavior

Tags:

.net

combobox

wpf

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.

like image 235
Luca Petrini Avatar asked Jul 05 '11 08:07

Luca Petrini


1 Answers

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

like image 144
Jonas Avatar answered Oct 19 '22 22:10

Jonas