WPF - 如何跳过选项卡导航中的标签?

use*_*389 3 navigation keyboard wpf xaml tabbing

我在用户控件内的网格​​内的堆栈面板内的项目控件内的控件模板内有一个堆栈面板(参见下面的xaml)。在内部堆栈面板中,有一个标签(Name =“NoComponentChosen”)和另一个堆栈面板(Name =“ComponentChosen”)。标签的可见性最初是折叠的。

控件模板有一个带有绑定的数据触发器。当绑定引用具有特定值时,标签 (NoComponentChosen) 变得可见并且堆栈面板折叠。

当我通过用户界面进行切换时,我想跳过标签/堆栈面板。我还希望仍然能够浏览 ChangeRequestView.xaml 中的其余内容(列表框和按钮)。

现在 - 当我选项卡 - 标签/堆栈面板最终被选中并被虚线矩形包围。这就是我想避免的。

这是我的 ChangeRequestView.xaml:

<UserControl x:Class="MyProgram.View.ChangeRequestView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
             xmlns:ListBoxBehavior="clr-namespace:MyProgram.Utility"
             mc:Ignorable="d" 
             d:DesignHeight="500" d:DesignWidth="300">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="50"/>
            <RowDefinition Height="35"/>
            <RowDefinition Height="45*"/>
            <RowDefinition Height="10*"/>
            <RowDefinition Height="20*"/>
            <RowDefinition Height="35"/>
        </Grid.RowDefinitions>

        <!--The title of the view-->
        <Label Grid.Row="0" Content="Change Requests" FontWeight="Bold" Margin="5,5,5,5" VerticalAlignment="Center" HorizontalAlignment="Center"/>

        <!--The component chosen-->
        <StackPanel Grid.Row="1" Orientation="Horizontal" Margin="5,0,0,0" IsHitTestVisible="False" Focusable="False">
            <ItemsControl>
                <ItemsControl.Template>
                    <ControlTemplate>
                        <StackPanel>
                            <StackPanel Name="ComponentChosen" Orientation="Horizontal">
                                <Label Content="Reference des.: " />
                                <Label Name="referenceDesignation" Content="{Binding Path=ReferenceDesignation, UpdateSourceTrigger=PropertyChanged}"/>
                            </StackPanel>
                            <Label Name="NoComponentChosen" Content="Choose a component" Visibility="Collapsed"/>
                        </StackPanel>
                        <ControlTemplate.Triggers>
                            <DataTrigger Binding="{Binding ReferenceDesignation}" Value="">
                                <Setter TargetName="ComponentChosen" Property="Visibility" Value="Collapsed"/>
                                <Setter TargetName="NoComponentChosen" Property="Visibility" Value="Visible"/>
                            </DataTrigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </ItemsControl.Template>
            </ItemsControl>
        </StackPanel>

        <ListBox Grid.Row="2" ... />
        <Button Grid.Row="3" ... />
        <Button Grid.Row="4" ... />
    </Grid>
</UserControl> 
Run Code Online (Sandbox Code Playgroud)


整个 UserControl/ChangeRequestView.xaml 是我的 MainWindow 的一部分 - 我不知道这是否有什么可说的。我在主窗口中浏览所有不同的视图,当我到达 ChangeRequestView 时,我想根据其中哪些未折叠来跳过标签/堆栈面板。

这是我的 MainWindow.xaml:

<Window x:Class="MyProgram.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:view="clr-namespace:MyProgram.View"
        xmlns:vm="clr-namespace:MyProgram.ViewModel"
        ...>
    <Grid>
        <Grid.RowDefinitions>
        <RowDefinition Height="20"/>
        <RowDefinition Height="309*"/>
        <RowDefinition Height="187*"/>
        <RowDefinition Height="120*"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="209*"/>
        <ColumnDefinition Width="558*"/>
        <ColumnDefinition Width="250*"/>
    </Grid.ColumnDefinitions>

    <Menu IsMainMenu="True" Name="Menu1" VerticalAlignment="Top" Grid.Row="0" Grid.ColumnSpan="3">
        <MenuItem Header="_File">
            <MenuItem Header="_Save changed change requests for current reference designation" 
                      InputGestureText="Ctrl+S" Command="{Binding Path=HotKeysSaveChangeRequestUpdateCmd}"/>
            <MenuItem Header="_Upload change requests for current project" 
                      InputGestureText="Ctrl+U" Command="{Binding Path=HotKeysUploadCmd}"/>
            <MenuItem Header="_Exit" ToolTip="Exit this program" 
                      InputGestureText="CTRL+X" Command="{Binding Path=ShutDownCmd}"/>
        </MenuItem>
    </Menu>

    <!--Search Region-->
    <Border Grid.Row="2" Grid.Column="0" Grid.RowSpan="2" Margin="3,1,1,3" BorderThickness="2,2,2,2" CornerRadius="4,4,4,4" BorderBrush="LightGray">
        <view:SearchView x:Name="SearchView"/>
    </Border>

    <!-- Project Region -->
    <Border Grid.Row="1" Grid.Column="0" Margin="3,3,1,1" BorderThickness="2,2,2,2" CornerRadius="4,4,4,4" BorderBrush="LightGray">
        <view:ProjectView x:Name="ProjectView" />
    </Border>

    <!-- Components Region -->
    <Border Grid.Row="1" Grid.Column="1" Grid.RowSpan="2" Margin="1,3,1,1" BorderThickness="2,2,2,2" CornerRadius="4,4,4,4" BorderBrush="LightGray">
        <view:ComponentView x:Name="ComponentView" />
    </Border>

    <!-- Change Request Region -->
    <Border Grid.Row="1" Grid.Column="2" Grid.RowSpan="2" Margin="1,3,3,1" BorderThickness="2,2,2,2" CornerRadius="4,4,4,4" BorderBrush="LightGray">
        <view:ChangeRequestView x:Name="ChangeRequestView" />
    </Border>

    <!-- Log Region -->
    <Border Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="2" Margin="1,1,3,3" BorderThickness="2,2,2,2" CornerRadius="4,4,4,4" BorderBrush="LightGray">
        <view:LogView x:Name="LogView" />
    </Border>

    </Grid>
    <Window.InputBindings>
        <KeyBinding Gesture="CTRL+U" Command="{Binding Path=HotKeysUploadCmd}"/>
        <KeyBinding Gesture="CTRL+S" Command="{Binding Path=HotKeysSaveChangeRequestUpdateCmd}"/>
        <KeyBinding Gesture="CTRL+X" Command="{Binding Path=ShutDownCmd}"/>
    </Window.InputBindings>
</Window> </br>
Run Code Online (Sandbox Code Playgroud)

对于很长的 xaml 文件,我深表歉意,但我认为我向您提供的信息越多,您就越容易帮助我解决此选项卡问题。

当我通过用户界面进行选项卡时,您对如何跳过标签“NoComponentChosen”/堆栈面板“ComponentChosen”有什么想法吗?

LPL*_*LPL 5

尝试在包含要跳过的元素的容器上使用KeyboardNavigation.TabNavigation 附加属性。KeyboardNavigationMode.None

KeyboardNavigation.TabNavigation="None"
Run Code Online (Sandbox Code Playgroud)