Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a ListBox in my WPF application where i am generating my ListBox items using a Datatemplate so in my Datatemplate i have some textboxes where i want taborder for Textboxes, How to achieve this i tried many ways but of no use.

Below is my XAML code :-

XML
<DataTemplate x:Key="DataTemplate1" >

<Grid Height="100" Width="1255" Background="#FFDA4F4F" KeyboardNavigation.DirectionalNavigation="Continue"  Margin="0,-8,0,0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="62*"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>

    <Grid x:Name="MainGrid" KeyboardNavigation.TabNavigation="Continue">
                           <Canvas Background="#F5F5F5" Height="30" HorizontalAlignment="Left" Margin="213,31,0,0" x:Name="canvas45" VerticalAlignment="Top" Width="92">

                            <TextBox Canvas.Left="5"  TabIndex="13" KeyboardNavigation.DirectionalNavigation="Continue" Text="{Binding Name}"   Canvas.Top="5" Height="20" Tag="{Binding}" LostFocus="txbbox1LostFocus"   x:Name="txbbox1" Width="82" PreviewTextInput="txbbbox1_PreviewTextInput" Background="Red" />

                        </Canvas>

                        <Canvas  Height="30" HorizontalAlignment="Right" Margin="0,31,186,0" x:Name="canvas46" VerticalAlignment="Top" Width="92">

                            <TextBox Canvas.Top="5"   TabIndex="14" Height="20"  x:Name="txbbox2" LostFocus="txbbox2LostFocus"   Text="{Binding txbbox2}"  Tag="{Binding}" PreviewTextInput="txbbox2_PreviewTextInput" Width="82" Canvas.Left="5" Background="red" />

                        </Canvas>

                        </Grid>

                    </Grid>
</DataTemplate>


And this is my listbox which i'm binding with my datatemplate.

HTML
<ListBox x:Name="ListBox1"  removed="Transparent"  ItemsSource="{Binding}" HorizontalAlignment="Left" Height="Auto" Margin="53,430,0,0" VerticalAlignment="Top" Width="1241" ItemTemplate="{DynamicResource DataTemplate1}"  BorderBrush="{x:Null}"   Style="{DynamicResource JListBox1}" ItemContainerStyle="{StaticResource ListBox1_ItemContainerStyle}" Grid.ColumnSpan="2" SelectionChanged="ListBox1_SelectionChanged"  />
Posted

1 solution

Can you please try :

Change TabIndex="0"...

You are nesting your controls, so, no need to maintain sequence. (not tested), hope it will solve your problem.

Also you are using LostFocus event for some process, check if it does redirect your focus to somewhere else...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900