我有一个带有以下 xaml 的窗口:
<Window x:Class="TestDemoApp.TreeViewWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="TreeViewWindow" Height="300" Width="300">
<Window.Resources>
<Style TargetType="Control" x:Key="FocusedStyle">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Rectangle StrokeThickness="1"
Stroke="Red"
StrokeDashArray="1 2 3 4"
SnapsToDevicePixels="true"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="TreeViewItem">
<Setter Property="IsTabStop" Value="True"/>
<Setter Property="Focusable" Value="True"/>
<Setter Property="FocusVisualStyle" Value="{StaticResource FocusedStyle}"/>
<Setter Property="KeyboardNavigation.TabNavigation" Value="Continue"/>
</Style>
<Style TargetType="ListViewItem">
<Setter Property="IsTabStop" Value="True"/>
<Setter Property="Focusable" Value="True"/>
<Setter Property="FocusVisualStyle" Value="{StaticResource FocusedStyle}"/>
<Setter Property="KeyboardNavigation.TabNavigation" Value="Continue"/>
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ListView TabIndex="1" BorderThickness="5" Focusable="True" IsTabStop="True" KeyboardNavigation.TabNavigation="Continue" FocusVisualStyle="{StaticResource FocusedStyle}">
<ListViewItem TabIndex="2" Content="List Item 1"/>
<ListViewItem TabIndex="3" Content="List Item 2"/>
</ListView>
<TreeView TabIndex="6" BorderThickness="5" Focusable="True" IsTabStop="True" KeyboardNavigation.TabNavigation="Continue" Grid.Row="1" FocusVisualStyle="{StaticResource FocusedStyle}">
<TreeView.Items>
<TreeViewItem TabIndex="7" Header="Tree Item 1">
<TreeViewItem Header="Tree Item 11"></TreeViewItem>
<TreeViewItem Header="Tree Item 12"/>
</TreeViewItem>
<TreeViewItem Header="Tree Item 2">
</TreeViewItem>
</TreeView.Items>
</TreeView>
</Grid>
</Window>
当我运行程序时,标签顺序是:
1.列表视图 2. 清单项目 1 3. 清单项目 2 4. 树视图 5. 树项目 1 6. 树项目 2 7. 列表视图(#1) 8. 列出第 1 项(#2) 9. 清单项目 2 (#3) 10. 树项目 2 (6#) 11+ 重复 #7 - #10
预期的行为是它会在进一步迭代时从 #1 重复到 #6,但是它会在任何后续迭代中跳过 #4 和 #5。
为什么是这样?我该如何解决?