如何在列表框项中设置Datatemplate文本框的Taborder? [英] How to set the taborder for the Datatemplate textboxes in a listbox item?

查看:80
本文介绍了如何在列表框项中设置Datatemplate文本框的Taborder?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的WPF应用程序中有一个ListBox,我使用Datatemplate生成ListBox项目,所以在我的Datatemplate中我有一些文本框,我想要Taborder for Textboxes,如何实现这个我尝试了很多方法但没有用。



以下是我的XAML代码: -



 <   DataTemplate     x:键  =  DataTemplate1   >  

< 网格 高度 = 100 宽度 < span class =code-keyword > = 1255 背景 = #FFDA4F4F KeyboardNavigation.DirectionalNavigation = 继续 < span class =code-attribute> 保证金 = 0,-8,0,0 >
< Grid.RowDefinitions >
< RowDefinition < span class =code-attribute>高度 = 62 * / >
< RowDefinition 高度 = * / >
< / Grid.RowDefinitions >

< 网格 x:名称 = MainGrid KeyboardNavigation.TabNavigation = 继续 >
< 画布 背景 = #F5F5F5 高度 = 30 Horizo​​ntalAlignment = 保证金 = 213,31,0,0 x:名称 = canvas45 VerticalAlignment = Top 宽度 = 92 >

< TextBox Canvas.Left = 5 TabIndex = 13 KeyboardNavigation.DirectionalNavigation =
继续 文本 = {Binding Name} Canvas.Top = 5 高度 = 20 标记 = {Binding} LostFocus = txbbox1LostFocus x:名称 = txbbox1 宽度 = 82 PreviewTextInput = txbbbox1_PreviewTextInput 背景 = 红色 / >

< / Canvas >

< 画布 高度 = 30 Horizo​​ntalAlignment = 保证金 = 0 ,31,186,0 x:名称 = canvas46 VerticalAlignment = Top 宽度 = 92 >

< < span class =code-leadattribute> TextBox Canvas.Top = 5 TabIndex = 14 高度 = 20 x:名称 = txbbox2 LostFocus = txbbox2LostFocus 文字 = {绑定txbbox2} 标记 = {Binding} < span class =code-attribute> PreviewTextInput = txbbox2_PreviewTextInput 宽度 = 82 Canvas.Left = 5 背景 = red / >

< / Canvas >

< / Grid >

< / Grid >
< / DataTemplate >





这是我的列表框,我与我的datatemplate绑定。



 <   ListBox     x:名称  =  ListBox1     已移除  = 透明      ItemsSource   =  {Binding}    Horizo​​ntalAlignment   =    高度  = 自动   保证金  =  53,430,0 ,0    VerticalAlignment   =  Top   宽度  =  1241    ItemTemplate   =  {DynamicResource DataTemplate1}      BorderBrush   =  {x:Null}       样式  =  {DynamicResource JListBox1}    ItemContainerStyle   =  {StaticResource ListBox1_ItemContainerStyle}    Grid.ColumnSpan   =  2    SelectionChanged   =   ListBox1_SelectionChanged      /  >  

解决方案

可以试试吗:



更改TabIndex =0...



你嵌套你的控件,所以,不需要维护序列。 (未经测试),希望它能解决您的问题。



此外,您正在使用LostFocus事件进行某些过程,检查它是否将焦点重定向到其他地方。

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 :-

<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.

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

解决方案

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...


这篇关于如何在列表框项中设置Datatemplate文本框的Taborder?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆