TreeViewItem元素中的c#选项卡索引

时间:2022-08-23 22:40:18

I have a simple TreeView, I'm not able to navigate in the TextBox with the focus. Do you have any suggestions???

我有一个简单的TreeView,我不能用焦点在文本框中导航。你有什么建议吗?

I have updated the xaml code for give you more details. I hope this is helpful. More Detail. More Detail. More Detail. More Detail. More Detail.

我已经更新了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>

2 个解决方案

#1


0  

TabIndex should be 1 and Focusable="true"

表索引应该为1,可调焦="true"

#2


0  

I found a solution, at least for my specific situation. The error was the ItemContainerStyle definition in the TreeView. Define the Window/UserControl resource's style for the TreeViewItem as below:

我找到了一个解决方案,至少是针对我的具体情况。错误是TreeView中的ItemContainerStyle定义。为TreeViewItem定义窗口/UserControl资源的样式如下:

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

#1


0  

TabIndex should be 1 and Focusable="true"

表索引应该为1,可调焦="true"

#2


0  

I found a solution, at least for my specific situation. The error was the ItemContainerStyle definition in the TreeView. Define the Window/UserControl resource's style for the TreeViewItem as below:

我找到了一个解决方案,至少是针对我的具体情况。错误是TreeView中的ItemContainerStyle定义。为TreeViewItem定义窗口/UserControl资源的样式如下:

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