我的WPF应用程序中有一个ListBox
,我使用ListBox
生成Datatemplate
个项目,所以在Datatemplate
我有一些文本框,我想要taborder for文本框,如何实现这一点我尝试了很多方法,但没有用。
以下是我的XAML
代码: -
<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>
这是我的列表框,我与我的datatemplate绑定。
<ListBox x:Name="ListBox1" Background="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" />
请给我任何建议如何做,提前致谢。
答案 0 :(得分:1)
不要为DataTemplate中的每个TextBox设置TabIndex,而是尝试将 TabNavigation 设置为循环模式,这会将光标自动移动到下一个可聚焦字段。
请点击此链接了解更多详情 http://social.technet.microsoft.com/wiki/contents/articles/25152.wpf-how-to-tab-between-items-in-a-listbox.aspx