树视图项元素中的 C# 选项卡索引

本文关键字:选项 索引 视图 元素 | 更新日期: 2023-09-27 17:56:37

我有一个简单的树视图,我无法使用焦点在文本框中导航。你有什么建议吗???

我已经更新了 xaml 代码,以便为您提供更多详细信息。我希望这是有帮助的。更多细节。更多细节。更多细节。更多细节。更多细节。

<StackPanel Orientation="Vertical" Margin="5">
    <StackPanel Orientation="Vertical">
                    <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" SharedSizeGroup="Column1"/>
                <ColumnDefinition Width="5"    SharedSizeGroup="Column2"/>
                <ColumnDefinition Width="*"   />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="28"/>
                <RowDefinition Height="28"/>  
            </Grid.RowDefinitions>
            <GridSplitter Grid.Column="1" Grid.RowSpan="2147483647" HorizontalAlignment="Left" Width="5" VerticalContentAlignment="Stretch" IsTabStop="False"/>
            <TextBlock Name="Number" Grid.Row="0" Grid.Column="0" Text="Number"/>
            <TextBox x:Name="TxtNumber" Grid.Row="0" Grid.Column="2" Text="{Binding Number}" TabIndex="0"/>
            <TextBlock Name="Name" Grid.Row="1" Grid.Column="0" Text="Name"/>
            <TextBox Grid.Row="1" Grid.Column="2" Text="{Binding Name}" TabIndex="1"/>
        </Grid>
    </StackPanel>
    <StackPanel Orientation="Vertical">
        <TextBlock Text="MyTree"/>
        <TreeView x:Name="MyTree" BorderThickness="0" Grid.IsSharedSizeScope="True" KeyboardNavigation.TabNavigation="Continue">
            <TreeView.Resources>
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black" />
                <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="Transparent" />
                <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}" Color="Black" />
            </TreeView.Resources>
            <TreeView.ItemContainerStyle>
                <Style TargetType="{x:Type TreeViewItem}">
                    <Setter Property="IsExpanded" Value="True" />
                    <Setter Property="KeyboardNavigation.TabNavigation" Value="Continue"/>
                </Style>
            </TreeView.ItemContainerStyle>
            <TreeViewItem>
                <TreeViewItem.Header>
                    <TextBlock Text="First Block" FontWeight="Bold"/>
                </TreeViewItem.Header>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" SharedSizeGroup="Column1"/>
                        <ColumnDefinition Width="5"    SharedSizeGroup="Column2"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="28"/>
                        <RowDefinition Height="28"/>
                        <RowDefinition Height="28"/>
                        <RowDefinition Height="28"/>
                    </Grid.RowDefinitions>
                    <GridSplitter Grid.Column="1" Grid.RowSpan="4" Width="5" HorizontalAlignment="Left" VerticalContentAlignment="Stretch" IsTabStop="False"/>
                    <TextBlock Grid.Row="0" Grid.Column="0" Text="A"/>
                    <CheckBox Grid.Row="0" Grid.Column="2" IsChecked="{Binding A}"/>
                    <TextBlock Grid.Row="1" Grid.Column="0" Text="B"/>
                    <TextBox Grid.Row="1" Grid.Column="2" Text="{Binding B}" Width="200"/>
                    <TextBlock Name="PassBin" Grid.Row="2" Grid.Column="0" Text="C"/>
                    <ComboBox x:Name="CbxPassBin" Grid.Row="2" Grid.Column="2" ItemsSource="{Binding C}" SelectedValue="{Binding SelectedC}"/>
                </Grid>
            </TreeViewItem>   
        </TreeView>
    </StackPanel>
</StackPanel>

树视图项元素中的 C# 选项卡索引

TabIndex 应该是1Focusable="true"

我找到了解决方案,至少针对我的具体情况。错误是树视图中ItemContainerStyle定义。定义TreeViewItemWindow/UserControl资源的样式,如下所示:

<Style TargetType="TreeViewItem">
    <Setter Property="KeyboardNavigation.TabNavigation" Value="Continue"/>
    <Setter Property="IsTabStop" Value="False"/>
  </Style>