Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何为listbox项中的Datatemplate文本框设置taborder?_C#_Wpf_Xaml_Listbox_Datatemplate - Fatal编程技术网

C# 如何为listbox项中的Datatemplate文本框设置taborder?

C# 如何为listbox项中的Datatemplate文本框设置taborder?,c#,wpf,xaml,listbox,datatemplate,C#,Wpf,Xaml,Listbox,Datatemplate,在我的WPF应用程序中,我有一个ListBox,我正在使用Datatemplate生成我的ListBox项目,因此在我的Datatemplate中,我有一些文本框,我想在其中使用taborder for textbox,如何实现这一点,我尝试了很多方法,但都没有用 下面是我的XAML代码:- <DataTemplate x:Key="DataTemplate1" > <Grid Height="100" Width="1255" Background="#FFDA4F

在我的WPF应用程序中,我有一个
ListBox
,我正在使用
Datatemplate
生成我的
ListBox
项目,因此在我的
Datatemplate
中,我有一些文本框,我想在其中使用taborder for textbox,如何实现这一点,我尝试了很多方法,但都没有用

下面是我的
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>

这是我的列表框,我正在用我的数据模板绑定它

<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"  />


请给我任何建议如何做,提前谢谢。

不要为DataTemplate中的每个文本框设置TabIndex,而是尝试将TabNavigation设置为Cycle模式,这将自动将光标移动到下一个可聚焦字段

请点击此链接了解更多详细信息