2013-05-10 60 views
1

我在一個控制模板內的一個控制模板內的一個控制模塊內的一個控制模塊內的一個控制模塊內的一個控制器內的一個控制器內的一個用戶控件(下面的xaml)。在內部的堆疊面板中有一個標籤(Name =「NoComponentChosen」)和另一個堆疊面板(Name =「ComponentChosen」)。標籤的可見性最初被摺疊。
WPF - 如何跳過標籤導航中的標籤?

controltemplate具有綁定的數據觸發器。當綁定引用具有特定值時,標籤(NoComponentChosen)變爲可見並且堆疊面板摺疊。

當我通過用戶界面切換時,我想跳過標籤/ stackpanel。我還希望能夠通過ChangeRequestView.xaml(列表框和按鈕)中的其他內容進行選項卡。

現在 - 當我標籤 - 標籤/ stackpanel最終被選中並被虛線矩形包圍。這是我想避免的。

這是我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> 


整個用戶控件/ ChangeRequestView.xaml是我的主窗口的一部分 - 我不知道是否有什麼話要說。我在我的MainWindow中選擇了所有不同的視圖,當我到達ChangeRequestView時,我想跳過標籤/ stackpanel,根據它們沒有被摺疊。

這是我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> 

我爲長XAML的文件道歉,但我想我提供給你的信息越多就越容易將是你幫助我解決這個問題。

當我通過用戶界面選項卡時,您是否有任何關於如何跳過標籤「NoComponentChosen」/ stackpanel「ComponentChosen」的想法?

回答

3

嘗試KeyboardNavigation.TabNavigation Attached PropertyKeyboardNavigationMode.None上的容器與你想跳過的元素。

KeyboardNavigation.TabNavigation="None" 
+0

這對我有用,當我將KeyboardNavigation.TabNavigation =「None」-property設置爲Grid.Row =「1」中最外面的堆棧面板時。我一直在你的答案(http://stackoverflow.com/questions/7745361/how-can-i-prevent-tabbing-to-a-usercontrol),但無法弄清楚如何正確使用它爲我的自己的問題。 感謝您對容器的幫助和指導:) – user2317389 2013-05-10 22:40:45

+0

如果我使用CTRL + Tab選項卡,儘管如此,堆棧面板不會被跳過 - 你知道這是怎麼回事嗎? – user2317389 2013-05-10 22:58:58

+0

還有一個附加屬性:[KeyboardNavigation.ControlTabNavigation](http://msdn.microsoft.com/en-us/library/system.windows.input.keyboardnavigation.controltabnavigation.aspx)。我認爲這將解決問題。 – LPL 2013-05-10 23:14:41