locked
Extreme tab order weirdness. Please help. RRS feed

  • Question

  • I have nine controls on two different grids that are all visible. All of the nine controls are set as Focusable and IsTabStop. Each control is assigned a TabIndex starting with 0 so that tab indexes are as follows: {0, 1, 2, 3, 4, 5, 6, 7, 8}

    However, when I run the application and tab through the controls here is the tab order I am getting: {0, 1, 4, 3, 2, 5, 6, 7, 8, 3, 4, 5, 6, 7, 8, ...}

    After this pattern completes it repeats the same incorrect pattern over and over. PLEASE help me.

    Friday, February 11, 2011 4:03 PM

Answers

  • Check your styles, your problem might be there. When I strip them out of the xaml and drop the code you provided into a stackpanel it tabs through in this order:

    1. Customers
    2. Name
    3. Last Name
    4. Quick Sale
    5. Add Customer
    6. Inventory
    7. Admin
    8. Police & Gun Rpt
    9. Configuration

    If it helps, here's what I used to test it:

    <Window
    	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    	x:Class="WpfApplication3.MainWindow"
    	x:Name="Window"
    	Title="MainWindow"
    	Width="640" Height="480">
    <StackPanel Orientation="Horizontal">
    	<Grid x:Name="grid_Panel_L" Width="120" HorizontalAlignment="Left">
    			<Grid.Background>
    				<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
    					<GradientStop Color="Black" Offset="1"/>
    					<GradientStop Color="#FF55AFD3"/>
    				</LinearGradientBrush>
    			</Grid.Background>
    			<Button x:Name="button_SidePanel_Inventory" Content="Inventory" Height="40" Margin="10,35,10,0" VerticalAlignment="Top" Foreground="White" 
    			TabIndex="1000"/>
    			<Button x:Name="button_SidePanel_Admin" Content="Admin" Height="40" Margin="10,85,10,0" VerticalAlignment="Top" 
    			TabIndex="1001" Foreground="White" />
    			<Button x:Name="button_SidePanel_PoliceAndGun" Height="40" Margin="10,135,10,0" VerticalAlignment="Top" Content="Police &amp; Gun Rpt" 
    			TabIndex="1002" Foreground="White" />
    			<Button x:Name="button_SidePanel_Configuration" Content="Configuration" Height="40" Margin="10,185,10,0" VerticalAlignment="Top" 
    			TabIndex="1003" Foreground="White" />
    		</Grid>
    
    <Grid x:Name="grid_CustomerLookUp" RenderTransformOrigin="0.5,0.5" Opacity="0.895" Grid.ColumnSpan="3" Background="Black">
    
    			<Grid.RenderTransform>
    				<TransformGroup>
    					<ScaleTransform/>
    					<SkewTransform/>
    					<RotateTransform/>
    					<TranslateTransform/>
    				</TransformGroup>
    			</Grid.RenderTransform>
    			<Grid.RowDefinitions>
    				<RowDefinition Height="0.498*"/>
    				<RowDefinition Height="0.502*"/>
    			</Grid.RowDefinitions>
    			<Button x:Name="button_Lookup_AddCustomer" Content="Add Customer" VerticalAlignment="Bottom" Margin="8,0,0,71.64" Grid.Row="1" Height="28" HorizontalAlignment="Left" Width="100" 
    			TabIndex="4" Foreground="White" />
    			<Button x:Name="button_Lookup_QuickSale" Content="Quick Sale" VerticalAlignment="Top" HorizontalAlignment="Right" Width="100" Height="28" 
    			TabIndex="3" Foreground="White" />
    			<Label x:Name="label_SearchFor" Content="Search for" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="8,8,0,0" FontWeight="Bold" Foreground="White"/>
    			<ComboBox x:Name="comboBox_Lookup_SearchTarget" HorizontalAlignment="Left" VerticalAlignment="Top" Width="120" Margin="8,37.96,0,0" ToolTip="Search for record type." Background="White" BorderBrush="{x:Null}" Foreground="Black" 
    			TabIndex="0" >
    				<ComboBoxItem Content="Customers" IsSelected="True" Foreground="Black" Background="White"/>
    				<ComboBoxItem Content="Inventory" Background="White"/>
    				<ComboBoxItem Content="IDs" Background="White"/>
    			</ComboBox>
    			<TextBox x:Name="textbox_Lookup_Search" TextWrapping="Wrap" VerticalAlignment="Top" Margin="256,37.96,0,0" FontStyle="Oblique" Foreground="#FFB4B4B4" Text="lastname" HorizontalAlignment="Left" Width="189.953" 
    			TabIndex="2" Background="White"/>
    			<Button x:Name="button_Lookup_EditCustomer" Content="Edit Customer" VerticalAlignment="Bottom" Margin="118.667,0,0,71.64" Grid.Row="1" Height="28" HorizontalAlignment="Left" Width="100" 
    			TabIndex="11" Foreground="White" Visibility="Hidden"/>
    			<Button x:Name="button_Lookup_Transactions" Content="Transactions" VerticalAlignment="Bottom" Margin="230.001,0,0,71.64" Grid.Row="1" Height="28" HorizontalAlignment="Left" Width="100" 
    			TabIndex="12" Foreground="White" Visibility="Hidden"/>
    			<Ellipse x:Name="ellipse_PathListBoxShape" Margin="112,127.6,112,156" Height="425" Grid.RowSpan="2"/>
    			<!--ec:PathListBox x:Name="pathlistbox_CustomerName" ItemsSource="{Binding}" ItemTemplate="{DynamicResource datatemplate_PathListBox}" HorizontalAlignment="Left" Width="100" Margin="28,97.6,0,167.733" SelectionChanged="pathlistbox_CustomerName_SelectionChanged" Foreground="White">
    				<ec:PathListBox.LayoutPaths>
    					<ec:LayoutPath SourceElement="{Binding ElementName=ellipse_PathListBoxShape}"/>
    				</ec:PathListBox.LayoutPaths>
    			</ec:PathListBox-->
    			<ComboBox x:Name="comboBox_Lookup_SpecificTarget" HorizontalAlignment="Left" VerticalAlignment="Top" Width="120" Margin="132,37.96,0,0" RenderTransformOrigin="0.875,-1.199"  
    			TabIndex="1" Foreground="Black" Background="White">
    				<ComboBoxItem Content="Name" IsSelected="True" Background="White"/>
    				<ComboBoxItem Content="Address" Background="White"/>
    				<ComboBoxItem Content="Phone" Background="White"/>
    				<ComboBoxItem Content="License" Background="White"/>
    			</ComboBox>
    			<Label x:Name="label_SearchBy" Content="Search by" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="132,8,0,0" FontWeight="Bold" Foreground="White"/>
    		</Grid>
    </StackPanel>
    </Window>
    


    Leon Terry
    TFK Labs
    • Proposed as answer by VLTII Friday, February 11, 2011 7:44 PM
    • Marked as answer by darrenlc Tuesday, February 15, 2011 4:41 PM
    Friday, February 11, 2011 7:43 PM

All replies

  • Can you post your xaml?
    Leon Terry
    TFK Labs
    Friday, February 11, 2011 4:05 PM
  • <Grid x:Name="grid_Panel_L" Width="120" HorizontalAlignment="Left">
    			<Grid.Background>
    				<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
    					<GradientStop Color="Black" Offset="1"/>
    					<GradientStop Color="#FF55AFD3"/>
    				</LinearGradientBrush>
    			</Grid.Background>
    			<Button x:Name="button_SidePanel_Inventory" Content="Inventory" Height="40" Margin="10,35,10,0" Style="{DynamicResource PWButtonStyle}" VerticalAlignment="Top" Foreground="White" TabIndex="1000" Click="button_SidePanel_Inventory_Click"/>
    			<Button x:Name="button_SidePanel_Admin" Content="Admin" Height="40" Margin="10,85,10,0" VerticalAlignment="Top" Click="button_SidePanel_Admin_Click" TabIndex="1001" Foreground="White" Style="{DynamicResource PWButtonStyle}"/>
    			<Button x:Name="button_SidePanel_PoliceAndGun" Height="40" Margin="10,135,10,0" VerticalAlignment="Top" Content="Police &amp; Gun Rpt" Click="button_SidePanel_PoliceAndGun_Click" TabIndex="1002" Foreground="White" Style="{DynamicResource PWButtonStyle}"/>
    			<Button x:Name="button_SidePanel_Configuration" Content="Configuration" Height="40" Margin="10,185,10,0" VerticalAlignment="Top" TabIndex="1003" Foreground="White" Style="{DynamicResource PWButtonStyle}" Click="button_SidePanel_Configuration_Click"/>
    		</Grid>
    
    <Grid x:Name="grid_CustomerLookUp" RenderTransformOrigin="0.5,0.5" Opacity="0.895" Margin="120,0" Grid.ColumnSpan="3">
    			<Grid.Background>
    				<ImageBrush ImageSource="Images/background_Panels_2.png"/>
    			</Grid.Background>
    			<Grid.RenderTransform>
    				<TransformGroup>
    					<ScaleTransform/>
    					<SkewTransform/>
    					<RotateTransform/>
    					<TranslateTransform/>
    				</TransformGroup>
    			</Grid.RenderTransform>
    			<Grid.RowDefinitions>
    				<RowDefinition Height="0.498*"/>
    				<RowDefinition Height="0.502*"/>
    			</Grid.RowDefinitions>
    			<Button x:Name="button_Lookup_AddCustomer" Content="Add Customer" VerticalAlignment="Bottom" Margin="8,0,0,71.64" Grid.Row="1" Height="28" HorizontalAlignment="Left" Width="100" Click="button_Lookup_AddCustomer_Click" TabIndex="4" Foreground="White" Style="{DynamicResource PWButtonStyle}"/>
    			<Button x:Name="button_Lookup_QuickSale" Content="Quick Sale" VerticalAlignment="Top" Margin="0,37.96,8,0" HorizontalAlignment="Right" Width="100" Height="28" TabIndex="3" Foreground="White" Style="{DynamicResource PWButtonStyle}"/>
    			<Label x:Name="label_SearchFor" Content="Search for" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="8,8,0,0" FontWeight="Bold" Foreground="White"/>
    			<ComboBox x:Name="comboBox_Lookup_SearchTarget" HorizontalAlignment="Left" VerticalAlignment="Top" Width="120" Margin="8,37.96,0,0" ToolTip="Search for record type." SelectionChanged="comboBox_Lookup_SearchTarget_SelectionChanged" Style="{DynamicResource myComboBoxStyle}" Background="White" BorderBrush="{x:Null}" Foreground="Black" TabIndex="0" >
    				<ComboBoxItem Content="Customers" IsSelected="True" Foreground="Black" Background="White"/>
    				<ComboBoxItem Content="Inventory" Background="White"/>
    				<ComboBoxItem Content="IDs" Background="White"/>
    			</ComboBox>
    			<TextBox x:Name="textbox_Lookup_Search" TextWrapping="Wrap" VerticalAlignment="Top" Margin="256,37.96,0,0" TextChanged="textbox_Lookup_Search_TextChanged" FontStyle="Oblique" Foreground="#FFB4B4B4" Text="lastname" GotFocus="textbox_Lookup_Search_GotFocus" HorizontalAlignment="Left" Width="189.953" TabIndex="2" Background="White"/>
    			<Button x:Name="button_Lookup_EditCustomer" Content="Edit Customer" VerticalAlignment="Bottom" Margin="118.667,0,0,71.64" Grid.Row="1" Height="28" HorizontalAlignment="Left" Width="100" Click="button_Lookup_EditCustomer_Click" TabIndex="11" Foreground="White" Style="{DynamicResource PWButtonStyle}" Visibility="Hidden"/>
    			<Button x:Name="button_Lookup_Transactions" Content="Transactions" VerticalAlignment="Bottom" Margin="230.001,0,0,71.64" Grid.Row="1" Height="28" HorizontalAlignment="Left" Width="100" Click="button_Lookup_Transactions_Click" TabIndex="12" Foreground="White" Style="{DynamicResource PWButtonStyle}" Visibility="Hidden"/>
    			<Ellipse x:Name="ellipse_PathListBoxShape" Margin="112,127.6,112,156" Height="425" Grid.RowSpan="2"/>
    			<ec:PathListBox x:Name="pathlistbox_CustomerName" ItemsSource="{Binding}" ItemTemplate="{DynamicResource datatemplate_PathListBox}" HorizontalAlignment="Left" Width="100" Margin="28,97.6,0,167.733" SelectionChanged="pathlistbox_CustomerName_SelectionChanged" Foreground="White">
    				<ec:PathListBox.LayoutPaths>
    					<ec:LayoutPath SourceElement="{Binding ElementName=ellipse_PathListBoxShape}"/>
    				</ec:PathListBox.LayoutPaths>
    			</ec:PathListBox>
    			<ComboBox x:Name="comboBox_Lookup_SpecificTarget" HorizontalAlignment="Left" VerticalAlignment="Top" Width="120" Margin="132,37.96,0,0" RenderTransformOrigin="0.875,-1.199" SelectionChanged="comboBox_Lookup_SpecificTarget_SelectionChanged" Style="{DynamicResource myComboBoxStyle}" TabIndex="1" Foreground="Black" Background="White">
    				<ComboBoxItem Content="Name" IsSelected="True" Background="White"/>
    				<ComboBoxItem Content="Address" Background="White"/>
    				<ComboBoxItem Content="Phone" Background="White"/>
    				<ComboBoxItem Content="License" Background="White"/>
    			</ComboBox>
    			<Label x:Name="label_SearchBy" Content="Search by" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="132,8,0,0" FontWeight="Bold" Foreground="White"/>
    		</Grid>
    

    Friday, February 11, 2011 4:22 PM
  • Look at your tab index values, they're way off of what your first post is saying :)
    Leon Terry
    TFK Labs
    • Proposed as answer by VLTII Friday, February 11, 2011 4:50 PM
    Friday, February 11, 2011 4:50 PM
  • I simplified the values in my initial post. The actual values are now: {0, 1, 2, 3, 4, 5, 6, 1000, 1001, 1002, 1003}

    There are two buttons that are invisible. Their TabIndex values were 11 and 12 in the XAML I posted above. I have now changed them to 5 and 6 respectively.

    The TabIndex values of 1000, 1001, 1002, 1003 are for buttons in a side panel that are always visible.

    I am still getting the exact same patter when I tab through the controls: {0, 1, 4, 3, 2, 1000, 1001, 1002, 1003, 3, 4, 1000, 1001, 1002, 1003, ...}

    Remember that controls 5 and 6 are invisible so they are not being tabbed through.

    Any idea what could be causing this odd pattern?

     

    Friday, February 11, 2011 5:14 PM
  • Check your styles, your problem might be there. When I strip them out of the xaml and drop the code you provided into a stackpanel it tabs through in this order:

    1. Customers
    2. Name
    3. Last Name
    4. Quick Sale
    5. Add Customer
    6. Inventory
    7. Admin
    8. Police & Gun Rpt
    9. Configuration

    If it helps, here's what I used to test it:

    <Window
    	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    	x:Class="WpfApplication3.MainWindow"
    	x:Name="Window"
    	Title="MainWindow"
    	Width="640" Height="480">
    <StackPanel Orientation="Horizontal">
    	<Grid x:Name="grid_Panel_L" Width="120" HorizontalAlignment="Left">
    			<Grid.Background>
    				<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
    					<GradientStop Color="Black" Offset="1"/>
    					<GradientStop Color="#FF55AFD3"/>
    				</LinearGradientBrush>
    			</Grid.Background>
    			<Button x:Name="button_SidePanel_Inventory" Content="Inventory" Height="40" Margin="10,35,10,0" VerticalAlignment="Top" Foreground="White" 
    			TabIndex="1000"/>
    			<Button x:Name="button_SidePanel_Admin" Content="Admin" Height="40" Margin="10,85,10,0" VerticalAlignment="Top" 
    			TabIndex="1001" Foreground="White" />
    			<Button x:Name="button_SidePanel_PoliceAndGun" Height="40" Margin="10,135,10,0" VerticalAlignment="Top" Content="Police &amp; Gun Rpt" 
    			TabIndex="1002" Foreground="White" />
    			<Button x:Name="button_SidePanel_Configuration" Content="Configuration" Height="40" Margin="10,185,10,0" VerticalAlignment="Top" 
    			TabIndex="1003" Foreground="White" />
    		</Grid>
    
    <Grid x:Name="grid_CustomerLookUp" RenderTransformOrigin="0.5,0.5" Opacity="0.895" Grid.ColumnSpan="3" Background="Black">
    
    			<Grid.RenderTransform>
    				<TransformGroup>
    					<ScaleTransform/>
    					<SkewTransform/>
    					<RotateTransform/>
    					<TranslateTransform/>
    				</TransformGroup>
    			</Grid.RenderTransform>
    			<Grid.RowDefinitions>
    				<RowDefinition Height="0.498*"/>
    				<RowDefinition Height="0.502*"/>
    			</Grid.RowDefinitions>
    			<Button x:Name="button_Lookup_AddCustomer" Content="Add Customer" VerticalAlignment="Bottom" Margin="8,0,0,71.64" Grid.Row="1" Height="28" HorizontalAlignment="Left" Width="100" 
    			TabIndex="4" Foreground="White" />
    			<Button x:Name="button_Lookup_QuickSale" Content="Quick Sale" VerticalAlignment="Top" HorizontalAlignment="Right" Width="100" Height="28" 
    			TabIndex="3" Foreground="White" />
    			<Label x:Name="label_SearchFor" Content="Search for" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="8,8,0,0" FontWeight="Bold" Foreground="White"/>
    			<ComboBox x:Name="comboBox_Lookup_SearchTarget" HorizontalAlignment="Left" VerticalAlignment="Top" Width="120" Margin="8,37.96,0,0" ToolTip="Search for record type." Background="White" BorderBrush="{x:Null}" Foreground="Black" 
    			TabIndex="0" >
    				<ComboBoxItem Content="Customers" IsSelected="True" Foreground="Black" Background="White"/>
    				<ComboBoxItem Content="Inventory" Background="White"/>
    				<ComboBoxItem Content="IDs" Background="White"/>
    			</ComboBox>
    			<TextBox x:Name="textbox_Lookup_Search" TextWrapping="Wrap" VerticalAlignment="Top" Margin="256,37.96,0,0" FontStyle="Oblique" Foreground="#FFB4B4B4" Text="lastname" HorizontalAlignment="Left" Width="189.953" 
    			TabIndex="2" Background="White"/>
    			<Button x:Name="button_Lookup_EditCustomer" Content="Edit Customer" VerticalAlignment="Bottom" Margin="118.667,0,0,71.64" Grid.Row="1" Height="28" HorizontalAlignment="Left" Width="100" 
    			TabIndex="11" Foreground="White" Visibility="Hidden"/>
    			<Button x:Name="button_Lookup_Transactions" Content="Transactions" VerticalAlignment="Bottom" Margin="230.001,0,0,71.64" Grid.Row="1" Height="28" HorizontalAlignment="Left" Width="100" 
    			TabIndex="12" Foreground="White" Visibility="Hidden"/>
    			<Ellipse x:Name="ellipse_PathListBoxShape" Margin="112,127.6,112,156" Height="425" Grid.RowSpan="2"/>
    			<!--ec:PathListBox x:Name="pathlistbox_CustomerName" ItemsSource="{Binding}" ItemTemplate="{DynamicResource datatemplate_PathListBox}" HorizontalAlignment="Left" Width="100" Margin="28,97.6,0,167.733" SelectionChanged="pathlistbox_CustomerName_SelectionChanged" Foreground="White">
    				<ec:PathListBox.LayoutPaths>
    					<ec:LayoutPath SourceElement="{Binding ElementName=ellipse_PathListBoxShape}"/>
    				</ec:PathListBox.LayoutPaths>
    			</ec:PathListBox-->
    			<ComboBox x:Name="comboBox_Lookup_SpecificTarget" HorizontalAlignment="Left" VerticalAlignment="Top" Width="120" Margin="132,37.96,0,0" RenderTransformOrigin="0.875,-1.199"  
    			TabIndex="1" Foreground="Black" Background="White">
    				<ComboBoxItem Content="Name" IsSelected="True" Background="White"/>
    				<ComboBoxItem Content="Address" Background="White"/>
    				<ComboBoxItem Content="Phone" Background="White"/>
    				<ComboBoxItem Content="License" Background="White"/>
    			</ComboBox>
    			<Label x:Name="label_SearchBy" Content="Search by" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="132,8,0,0" FontWeight="Bold" Foreground="White"/>
    		</Grid>
    </StackPanel>
    </Window>
    


    Leon Terry
    TFK Labs
    • Proposed as answer by VLTII Friday, February 11, 2011 7:44 PM
    • Marked as answer by darrenlc Tuesday, February 15, 2011 4:41 PM
    Friday, February 11, 2011 7:43 PM
  • Thank you for helping! The problem was indeed in the styles.
    Tuesday, February 15, 2011 4:42 PM