我有一个ListView水平呈现项目 . 每个项目都是一列Grid . 外观是网格,其中列数是动态的 . 除了标签导航之外,所有这些都有效,看起来我想要它 . 我在ListView上设置 KeyboardNavigation.TabNavigation="Continue"
并在ItemContainerStyle上将KeyboardNavigation.IsTabStop设置为false,这允许我通过项目中的每一行,然后到下一项,等等 . 但是,我想从第一项中选项卡将第一个项目中的行放到第二个项目中的第一行等,然后转到下一行 .
防爆 .
Item1Row1 - > Item2Row1 - > Item3Row1 - > ... Item1Row2 - > Item2Row2 - > Item3Row2 - > ...
我为每个单元格中的控件设置了标签索引(我测试过的是正确的),但我无法弄清楚在ListView / ListViewItems中启用TabIndex所需的设置 . 任何帮助将不胜感激 . 这是xaml ......
<ListView VerticalAlignment="Top" Background="Transparent" BorderThickness="0" KeyboardNavigation.TabNavigation="Continue" ItemsSource="{Binding RawProductDataItemViewModels}">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="Focusable" Value="False"/>
<Setter Property="KeyboardNavigation.IsTabStop" Value="False"/>
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<DataTemplate>
<Grid VerticalAlignment="Top" Margin="2.5,0,2.5,0">
<Grid.RowDefinitions>
<RowDefinition SharedSizeGroup="ButtonAndGridGroup"/>
<RowDefinition SharedSizeGroup="ButtonAndGridGroup"/>
<RowDefinition SharedSizeGroup="ButtonAndGridGroup"/>
<RowDefinition SharedSizeGroup="ButtonAndGridGroup"/>
<RowDefinition SharedSizeGroup="ButtonAndGridGroup"/>
<RowDefinition SharedSizeGroup="ButtonAndGridGroup"/>
<RowDefinition SharedSizeGroup="ButtonAndGridGroup"/>
<RowDefinition SharedSizeGroup="ButtonAndGridGroup"/>
<RowDefinition SharedSizeGroup="ButtonAndGridGroup"/>
<RowDefinition SharedSizeGroup="ButtonAndGridGroup"/>
<RowDefinition SharedSizeGroup="ButtonAndGridGroup"/>
</Grid.RowDefinitions>
<TextBlock Margin="5,4,0,0" Grid.Row="0">
<TextBlock.Text>
<MultiBinding StringFormat="Lane #{0}">
<Binding Path="Lane"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<TextBox Grid.Row="1" Margin="0,4,0,0" Width="75" Text="{Binding RollNumber, StringFormat='{}{0:#####-#}', TargetNullValue=''}"
TabIndex="{Binding Lane, Converter={StaticResource IntegersTo2DIndex}, ConverterParameter=1}"/>
<TextBox Grid.Row="2" Margin="0,4,0,0" Width="75" Text="{Binding PCode}"
TabIndex="{Binding Lane, Converter={StaticResource IntegersTo2DIndex}, ConverterParameter=2}"/>
<TextBox Grid.Row="3" Margin="0,4,0,0" Width="75" Text="{Binding RollWidth}"
TabIndex="{Binding Lane, Converter={StaticResource IntegersTo2DIndex}, ConverterParameter=3}"/>
<TextBox Grid.Row="4" Margin="0,4,0,0" Width="75" Text="{Binding RollWeight}"
TabIndex="{Binding Lane, Converter={StaticResource IntegersTo2DIndex}, ConverterParameter=4}"/>
<TextBox Grid.Row="5" Margin="0,4,0,0" Width="75" Text="{Binding GrossWeight}"
TabIndex="{Binding Lane, Converter={StaticResource IntegersTo2DIndex}, ConverterParameter=5}"/>
<TextBox Grid.Row="6" Margin="0,4,0,0" Width="75" Text="{Binding BurnWeight}"
TabIndex="{Binding Lane, Converter={StaticResource IntegersTo2DIndex}, ConverterParameter=6}"/>
<TextBox Grid.Row="7" Margin="0,4,0,0" Width="75" Text="{Binding SqFtWeight}"
TabIndex="{Binding Lane, Converter={StaticResource IntegersTo2DIndex}, ConverterParameter=7}"/>
<TextBox Grid.Row="8" Margin="0,4,0,0" Width="75" Text="{Binding Cure}"
TabIndex="{Binding Lane, Converter={StaticResource IntegersTo2DIndex}, ConverterParameter=8}"/>
<TextBox Grid.Row="9" Margin="0,4,0,0" Width="75" Text="{Binding Rigidity}"
TabIndex="{Binding Lane, Converter={StaticResource IntegersTo2DIndex}, ConverterParameter=9}"/>
<TextBox Grid.Row="10" Margin="0,4,0,0" Width="75" Text="{Binding Telescope}"
TabIndex="{Binding Lane, Converter={StaticResource IntegersTo2DIndex}, ConverterParameter=10}"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
1 回答
我决定在后面的代码中处理这个问题 . 我删除了xaml中文本框上的选项卡索引 . 解决方案并不漂亮,但在我看来,它比删除列表框并对所有通道进行编码更好,以便我可以使用选项卡索引 .
Preview Key Down Handler on ListView:
Move Focus Methods: