2016-11-11 12 views
3

メニュー項目のビジュアルスタイルはほとんど私が望む方法ではありますが、以前のものとは別のものを使用していた縦線を隠す方法を理解できませんアイコンの列とテキストの列。アイコン列とテキストの間のMenuItemの縦線を取り除く方法

私はアイコンCOLUMNを削除しようとしている他の多くの質問と回答を見てきましたが、私がここで見つけた他の同様の質問と回答は、この行をアイコン列だけ削除して、それを隠すようにメニュー項目の背景を設定します(これは避けたいものです)。

あなたはかろうじて私のテストメニュー項目の「S」と「T」の間で実行されている、ここでそれを行うことができます:

enter image description here

あなたはprobibly期待通り私のスタイルとテンプレートがこれまでにありそれは見て:

<SolidColorBrush x:Key="MenuItem.Highlight.Background" Color="#3D26A0DA"/> 
    <SolidColorBrush x:Key="MenuItem.Highlight.Border" Color="#FF26A0DA"/> 
    <SolidColorBrush x:Key="Menu.Disabled.Foreground" Color="#FF707070"/> 
    <SolidColorBrush x:Key="MenuItem.Highlight.Disabled.Background" Color="#0A000000"/> 
    <SolidColorBrush x:Key="MenuItem.Highlight.Disabled.Border" Color="#21000000"/> 
    <SolidColorBrush x:Key="MenuItem.Selected.Border" Color="#FF26A0DA"/> 
    <SolidColorBrush x:Key="MenuItem.Selected.Background" Color="#3D26A0DA"/> 
    <Geometry x:Key="Checkmark">F1 M 10.0,1.2 L 4.7,9.1 L 4.5,9.1 L 0,5.2 L 1.3,3.5 L 4.3,6.1L 8.3,0 L 10.0,1.2 Z</Geometry> 
    <SolidColorBrush x:Key="Menu.Static.Foreground" Color="#FF212121"/> 
    <SolidColorBrush x:Key="Menu.Static.Border" Color="#FF999999"/> 
    <SolidColorBrush x:Key="Menu.Static.Background" Color="#FFF0F0F0"/> 
    <SolidColorBrush x:Key="Menu.Static.Separator" Color="#00000000"/> 

    <ControlTemplate x:Key="MenuContentSubmenuItemTemplateKey" TargetType="{x:Type MenuItem}"> 
     <Border x:Name="templateRoot" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Height="22" SnapsToDevicePixels="true"> 
      <Grid Margin="-1"> 
       <Grid.ColumnDefinitions> 
        <ColumnDefinition SharedSizeGroup="MenuItemIconColumnGroup" Width="0"/> 
        <ColumnDefinition Width="13"/> 
        <ColumnDefinition Width="*"/> 
        <ColumnDefinition Width="30"/> 
        <ColumnDefinition SharedSizeGroup="MenuItemIGTColumnGroup" Width="Auto"/> 
        <ColumnDefinition Width="20"/> 
       </Grid.ColumnDefinitions> 
       <ContentPresenter x:Name="Icon" ContentSource="Icon" HorizontalAlignment="Center" Height="16" Margin="3" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center" Width="16"/> 
       <Border x:Name="GlyphPanel" BorderBrush="{StaticResource MenuItem.Selected.Border}" BorderThickness="1" Background="{StaticResource MenuItem.Selected.Background}" ClipToBounds="False" HorizontalAlignment="Center" Height="22" Margin="-1,0,0,0" Visibility="Hidden" VerticalAlignment="Center" Width="22"> 
        <Path x:Name="Glyph" Data="{StaticResource Checkmark}" Fill="{StaticResource Menu.Static.Foreground}" FlowDirection="LeftToRight" Height="11" Width="10"/> 
       </Border> 
       <ContentPresenter x:Name="menuHeaderContainer" Grid.Column="2" ContentSource="Header" HorizontalAlignment="Left" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center"/> 
       <TextBlock x:Name="menuGestureText" Grid.Column="4" Margin="{TemplateBinding Padding}" Opacity="0.7" Text="{TemplateBinding InputGestureText}" VerticalAlignment="Center"/> 
      </Grid> 
     </Border> 
     <ControlTemplate.Triggers> 
      <Trigger Property="Icon" Value="{x:Null}"> 
       <Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/> 
      </Trigger> 
      <Trigger Property="IsChecked" Value="True"> 
       <Setter Property="Visibility" TargetName="GlyphPanel" Value="Visible"/> 
       <Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/> 
      </Trigger> 
      <Trigger Property="IsHighlighted" Value="True"> 
       <Setter Property="Background" TargetName="templateRoot" Value="{x:Null}"/> 
       <Setter Property="BorderBrush" TargetName="templateRoot" Value="{x:Null}"/> 
      </Trigger> 
      <Trigger Property="IsEnabled" Value="False"> 
       <Setter Property="TextElement.Foreground" TargetName="templateRoot" Value="{StaticResource Menu.Disabled.Foreground}"/> 
       <Setter Property="Fill" TargetName="Glyph" Value="{StaticResource Menu.Disabled.Foreground}"/> 
      </Trigger> 
      <MultiTrigger> 
       <MultiTrigger.Conditions> 
        <Condition Property="IsHighlighted" Value="True"/> 
        <Condition Property="IsEnabled" Value="False"/> 
       </MultiTrigger.Conditions> 
       <Setter Property="Background" TargetName="templateRoot" Value="{StaticResource MenuItem.Highlight.Disabled.Background}"/> 
       <Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource MenuItem.Highlight.Disabled.Border}"/> 
      </MultiTrigger> 
     </ControlTemplate.Triggers> 
    </ControlTemplate> 

    <Geometry x:Key="UpArrow">M 0,4 L 3.5,0 L 7,4 Z</Geometry> 
    <Style x:Key="MenuScrollButton" BasedOn="{x:Null}" TargetType="{x:Type RepeatButton}"> 
     <Setter Property="ClickMode" Value="Hover"/> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="{x:Type RepeatButton}"> 
        <Border x:Name="templateRoot" BorderBrush="Transparent" BorderThickness="1" Background="Transparent" SnapsToDevicePixels="true"> 
         <ContentPresenter HorizontalAlignment="Center" Margin="6" VerticalAlignment="Center"/> 
        </Border> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 
    <MenuScrollingVisibilityConverter x:Key="MenuScrollingVisibilityConverter"/> 
    <Geometry x:Key="DownArrow">M 0,0 L 3.5,4 L 7,0 Z</Geometry> 
    <Style x:Key="{ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}" BasedOn="{x:Null}" TargetType="{x:Type ScrollViewer}"> 
     <Setter Property="HorizontalScrollBarVisibility" Value="Hidden"/> 
     <Setter Property="VerticalScrollBarVisibility" Value="Auto"/> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="{x:Type ScrollViewer}"> 
        <Grid SnapsToDevicePixels="true"> 
         <Grid.ColumnDefinitions> 
          <ColumnDefinition Width="*"/> 
         </Grid.ColumnDefinitions> 
         <Grid.RowDefinitions> 
          <RowDefinition Height="Auto"/> 
          <RowDefinition Height="*"/> 
          <RowDefinition Height="Auto"/> 
         </Grid.RowDefinitions> 
         <Border Grid.Column="0" Grid.Row="1"> 
          <ScrollContentPresenter CanContentScroll="{TemplateBinding CanContentScroll}" Margin="{TemplateBinding Padding}"/> 
         </Border> 
         <RepeatButton Grid.Column="0" CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}" Command="{x:Static ScrollBar.LineUpCommand}" Focusable="false" Grid.Row="0" Style="{StaticResource MenuScrollButton}"> 
          <RepeatButton.Visibility> 
           <MultiBinding ConverterParameter="0" Converter="{StaticResource MenuScrollingVisibilityConverter}" FallbackValue="Visibility.Collapsed"> 
            <Binding Path="ComputedVerticalScrollBarVisibility" RelativeSource="{RelativeSource TemplatedParent}"/> 
            <Binding Path="VerticalOffset" RelativeSource="{RelativeSource TemplatedParent}"/> 
            <Binding Path="ExtentHeight" RelativeSource="{RelativeSource TemplatedParent}"/> 
            <Binding Path="ViewportHeight" RelativeSource="{RelativeSource TemplatedParent}"/> 
           </MultiBinding> 
          </RepeatButton.Visibility> 
          <Path Data="{StaticResource UpArrow}" Fill="{StaticResource Menu.Static.Foreground}"/> 
         </RepeatButton> 
         <RepeatButton Grid.Column="0" CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}" Command="{x:Static ScrollBar.LineDownCommand}" Focusable="false" Grid.Row="2" Style="{StaticResource MenuScrollButton}"> 
          <RepeatButton.Visibility> 
           <MultiBinding ConverterParameter="100" Converter="{StaticResource MenuScrollingVisibilityConverter}" FallbackValue="Visibility.Collapsed"> 
            <Binding Path="ComputedVerticalScrollBarVisibility" RelativeSource="{RelativeSource TemplatedParent}"/> 
            <Binding Path="VerticalOffset" RelativeSource="{RelativeSource TemplatedParent}"/> 
            <Binding Path="ExtentHeight" RelativeSource="{RelativeSource TemplatedParent}"/> 
            <Binding Path="ViewportHeight" RelativeSource="{RelativeSource TemplatedParent}"/> 
           </MultiBinding> 
          </RepeatButton.Visibility> 
          <Path Data="{StaticResource DownArrow}" Fill="{StaticResource Menu.Static.Foreground}"/> 
         </RepeatButton> 
        </Grid> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 
    <ControlTemplate x:Key="MenuContentTopLevelHeaderTemplateKey" TargetType="{x:Type MenuItem}"> 
     <Border x:Name="templateRoot" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true"> 
      <Grid VerticalAlignment="Center"> 
       <Grid.ColumnDefinitions> 
        <ColumnDefinition Width="Auto"/> 
        <ColumnDefinition Width="Auto"/> 
       </Grid.ColumnDefinitions> 
       <ContentPresenter x:Name="Icon" ContentSource="Icon" HorizontalAlignment="Center" Height="16" Margin="3" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center" Width="16"/> 
       <Path x:Name="GlyphPanel" Data="{StaticResource Checkmark}" Fill="{TemplateBinding Foreground}" FlowDirection="LeftToRight" Margin="3" Visibility="Collapsed" VerticalAlignment="Center"/> 
       <ContentPresenter Grid.Column="1" ContentSource="Header" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> 
       <Popup x:Name="PART_Popup" AllowsTransparency="true" Focusable="false" IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}" Placement="Bottom" PlacementTarget="{Binding ElementName=templateRoot}"> 
        <Border x:Name="SubMenuBorder" BorderBrush="{StaticResource Menu.Static.Border}" BorderThickness="1" Background="{StaticResource Menu.Static.Background}" Padding="2"> 
         <ScrollViewer x:Name="SubMenuScrollViewer" Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}"> 
          <Grid RenderOptions.ClearTypeHint="Enabled"> 
           <!--<Canvas HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0"> 
            <Rectangle x:Name="OpaqueRect" Fill="{Binding Background, ElementName=SubMenuBorder}" Height="{Binding ActualHeight, ElementName=SubMenuBorder}" Width="{Binding ActualWidth, ElementName=SubMenuBorder}"/> 
           </Canvas> 
           <Rectangle Visibility="Collapsed" Fill="{StaticResource Menu.Static.Separator}" HorizontalAlignment="Left" Margin="29,2,0,2" Width="1"/>--> 
           <ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Cycle" Grid.IsSharedSizeScope="true" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" KeyboardNavigation.TabNavigation="Cycle"/> 
          </Grid> 
         </ScrollViewer> 
        </Border> 
       </Popup> 
      </Grid> 
     </Border> 
     <ControlTemplate.Triggers> 
      <Trigger Property="IsSuspendingPopupAnimation" Value="true"> 
       <Setter Property="PopupAnimation" TargetName="PART_Popup" Value="None"/> 
      </Trigger> 
      <Trigger Property="Icon" Value="{x:Null}"> 
       <Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/> 
      </Trigger> 
      <Trigger Property="IsChecked" Value="true"> 
       <Setter Property="Visibility" TargetName="GlyphPanel" Value="Visible"/> 
       <Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/> 
      </Trigger> 
      <Trigger Property="IsHighlighted" Value="True"> 
       <Setter Property="Background" TargetName="templateRoot" Value="{x:Null}"/> 
       <Setter Property="BorderBrush" TargetName="templateRoot" Value="{x:Null}"/> 
      </Trigger> 
      <Trigger Property="IsEnabled" Value="False"> 
       <Setter Property="TextElement.Foreground" TargetName="templateRoot" Value="{StaticResource Menu.Disabled.Foreground}"/> 
       <Setter Property="Fill" TargetName="GlyphPanel" Value="{StaticResource Menu.Disabled.Foreground}"/> 
      </Trigger> 
      <Trigger Property="ScrollViewer.CanContentScroll" SourceName="SubMenuScrollViewer" Value="false"> 
       <Setter Property="Canvas.Top" TargetName="OpaqueRect" Value="{Binding VerticalOffset, ElementName=SubMenuScrollViewer}"/> 
       <Setter Property="Canvas.Left" TargetName="OpaqueRect" Value="{Binding HorizontalOffset, ElementName=SubMenuScrollViewer}"/> 
      </Trigger> 
     </ControlTemplate.Triggers> 
    </ControlTemplate> 
    <ControlTemplate x:Key="MenuContentTopLevelItemTemplateKey" TargetType="{x:Type MenuItem}"> 
     <Border x:Name="templateRoot" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true"> 
      <Grid VerticalAlignment="Center"> 
       <Grid.ColumnDefinitions> 
        <ColumnDefinition Width="Auto"/> 
        <ColumnDefinition Width="Auto"/> 
       </Grid.ColumnDefinitions> 
       <ContentPresenter x:Name="Icon" ContentSource="Icon" HorizontalAlignment="Center" Height="16" Margin="3" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center" Width="16"/> 
       <Path x:Name="GlyphPanel" Data="{StaticResource Checkmark}" Fill="{StaticResource Menu.Static.Foreground}" FlowDirection="LeftToRight" Margin="3" Visibility="Collapsed" VerticalAlignment="Center"/> 
       <ContentPresenter Grid.Column="1" ContentSource="Header" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> 
      </Grid> 
     </Border> 
     <ControlTemplate.Triggers> 
      <Trigger Property="Icon" Value="{x:Null}"> 
       <Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/> 
      </Trigger> 
      <Trigger Property="IsChecked" Value="true"> 
       <Setter Property="Visibility" TargetName="GlyphPanel" Value="Visible"/> 
       <Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/> 
      </Trigger> 
      <Trigger Property="IsHighlighted" Value="True"> 
       <Setter Property="Background" TargetName="templateRoot" Value="{x:Null}"/> 
       <Setter Property="BorderBrush" TargetName="templateRoot" Value="{x:Null}"/> 
      </Trigger> 
      <Trigger Property="IsEnabled" Value="False"> 
       <Setter Property="TextElement.Foreground" TargetName="templateRoot" Value="{StaticResource Menu.Disabled.Foreground}"/> 
       <Setter Property="Fill" TargetName="GlyphPanel" Value="{StaticResource Menu.Disabled.Foreground}"/> 
      </Trigger> 
      <MultiTrigger> 
       <MultiTrigger.Conditions> 
        <Condition Property="IsHighlighted" Value="True"/> 
        <Condition Property="IsEnabled" Value="False"/> 
       </MultiTrigger.Conditions> 
       <Setter Property="Background" TargetName="templateRoot" Value="{StaticResource MenuItem.Highlight.Disabled.Background}"/> 
       <Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource MenuItem.Highlight.Disabled.Border}"/> 
      </MultiTrigger> 
     </ControlTemplate.Triggers> 
    </ControlTemplate> 
    <Geometry x:Key="RightArrow">M 0,0 L 4,3.5 L 0,7 Z</Geometry> 
    <ControlTemplate x:Key="MenuContentSubmenuHeaderTemplateKey" TargetType="{x:Type MenuItem}"> 
     <Border x:Name="templateRoot" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Height="22" SnapsToDevicePixels="true"> 
      <Grid Margin="-1"> 
       <Grid.ColumnDefinitions> 
        <ColumnDefinition SharedSizeGroup="MenuItemIconColumnGroup" Width="0"/> 
        <ColumnDefinition Width="13"/> 
        <ColumnDefinition Width="*"/> 
        <ColumnDefinition Width="30"/> 
        <ColumnDefinition SharedSizeGroup="MenuItemIGTColumnGroup" Width="Auto"/> 
        <ColumnDefinition Width="20"/> 
       </Grid.ColumnDefinitions> 
       <ContentPresenter x:Name="Icon" ContentSource="Icon" HorizontalAlignment="Center" Height="16" Margin="3" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center" Width="16"/> 
       <Border x:Name="GlyphPanel" BorderBrush="{StaticResource MenuItem.Highlight.Border}" BorderThickness="1" Background="{StaticResource MenuItem.Highlight.Background}" Height="22" Margin="-1,0,0,0" Visibility="Hidden" VerticalAlignment="Center" Width="22"> 
        <Path x:Name="Glyph" Data="{DynamicResource Checkmark}" Fill="{StaticResource Menu.Static.Foreground}" FlowDirection="LeftToRight" Height="11" Width="9"/> 
       </Border> 
       <ContentPresenter Grid.Column="2" ContentSource="Header" HorizontalAlignment="Left" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center"/> 
       <TextBlock Grid.Column="4" Margin="{TemplateBinding Padding}" Opacity="0.7" Text="{TemplateBinding InputGestureText}" VerticalAlignment="Center"/> 
       <Path x:Name="RightArrow" Grid.Column="5" Data="{StaticResource RightArrow}" Fill="{StaticResource Menu.Static.Foreground}" HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Center"/> 
       <Popup x:Name="PART_Popup" AllowsTransparency="true" Focusable="false" HorizontalOffset="-2" IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}" Placement="Right" VerticalOffset="-3"> 
        <Border x:Name="SubMenuBorder" BorderBrush="{StaticResource Menu.Static.Border}" BorderThickness="1" Background="{StaticResource Menu.Static.Background}" Padding="2"> 
         <ScrollViewer x:Name="SubMenuScrollViewer" Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}"> 
          <Grid RenderOptions.ClearTypeHint="Enabled"> 
           <!--<Canvas HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0"> 
            <Rectangle x:Name="OpaqueRect" Fill="{Binding Background, ElementName=SubMenuBorder}" Height="{Binding ActualHeight, ElementName=SubMenuBorder}" Width="{Binding ActualWidth, ElementName=SubMenuBorder}"/> 
           </Canvas> 
           <Rectangle Visibility="Collapsed" Fill="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}" HorizontalAlignment="Left" Margin="29,2,0,2" Width="1"/>--> 
           <ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Cycle" Grid.IsSharedSizeScope="true" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" KeyboardNavigation.TabNavigation="Cycle"/> 
          </Grid> 
         </ScrollViewer> 
        </Border> 
       </Popup> 
      </Grid> 
     </Border> 
     <ControlTemplate.Triggers> 
      <Trigger Property="IsSuspendingPopupAnimation" Value="true"> 
       <Setter Property="PopupAnimation" TargetName="PART_Popup" Value="None"/> 
      </Trigger> 
      <Trigger Property="Icon" Value="{x:Null}"> 
       <Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/> 
      </Trigger> 
      <Trigger Property="IsChecked" Value="True"> 
       <Setter Property="Visibility" TargetName="GlyphPanel" Value="Visible"/> 
       <Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/> 
      </Trigger> 
      <Trigger Property="IsHighlighted" Value="True"> 
       <Setter Property="Background" TargetName="templateRoot" Value="{x:Null}"/> 
       <Setter Property="BorderBrush" TargetName="templateRoot" Value="{x:Null}"/> 
      </Trigger> 
      <Trigger Property="IsEnabled" Value="False"> 
       <Setter Property="TextElement.Foreground" TargetName="templateRoot" Value="{StaticResource Menu.Disabled.Foreground}"/> 
       <Setter Property="Fill" TargetName="Glyph" Value="{StaticResource Menu.Disabled.Foreground}"/> 
       <Setter Property="Fill" TargetName="RightArrow" Value="{StaticResource Menu.Disabled.Foreground}"/> 
      </Trigger> 
      <Trigger Property="ScrollViewer.CanContentScroll" SourceName="SubMenuScrollViewer" Value="false"> 
       <Setter Property="Canvas.Top" TargetName="OpaqueRect" Value="{Binding VerticalOffset, ElementName=SubMenuScrollViewer}"/> 
       <Setter Property="Canvas.Left" TargetName="OpaqueRect" Value="{Binding HorizontalOffset, ElementName=SubMenuScrollViewer}"/> 
      </Trigger> 
     </ControlTemplate.Triggers> 
    </ControlTemplate> 
    <Style x:Key="MenuItemStyle1" TargetType="{x:Type MenuItem}"> 
     <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/> 
     <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/> 
     <Setter Property="Background" Value="Transparent"/> 
     <Setter Property="BorderBrush" Value="Transparent"/> 
     <Setter Property="BorderThickness" Value="1"/> 
     <Setter Property="ScrollViewer.PanningMode" Value="Both"/> 
     <Setter Property="Stylus.IsFlicksEnabled" Value="False"/> 
     <Setter Property="Template" Value="{DynamicResource MenuContentSubmenuItemTemplateKey}"/> 
     <Style.Triggers> 
      <Trigger Property="Role" Value="TopLevelHeader"> 
       <Setter Property="Background" Value="Transparent"/> 
       <Setter Property="BorderBrush" Value="Transparent"/> 
       <Setter Property="Foreground" Value="{StaticResource Menu.Static.Foreground}"/> 
       <Setter Property="Template" Value="{DynamicResource MenuContentTopLevelHeaderTemplateKey}"/> 
       <Setter Property="Padding" Value="6,0"/> 
      </Trigger> 
      <Trigger Property="Role" Value="TopLevelItem"> 
       <Setter Property="Background" Value="{StaticResource Menu.Static.Background}"/> 
       <Setter Property="BorderBrush" Value="{StaticResource Menu.Static.Border}"/> 
       <Setter Property="Foreground" Value="{StaticResource Menu.Static.Foreground}"/> 
       <Setter Property="Template" Value="{DynamicResource MenuContentTopLevelItemTemplateKey}"/> 
       <Setter Property="Padding" Value="6,0"/> 
      </Trigger> 
      <Trigger Property="Role" Value="SubmenuHeader"> 
       <Setter Property="Template" Value="{DynamicResource MenuContentSubmenuHeaderTemplateKey}"/> 
      </Trigger> 
     </Style.Triggers> 
    </Style> 
+0

提供されたコードは実行されません:あなたが 'TargetName =" OpaqueRect "'を参照しているいくつかの場所。それらを削除すると、 ''コードが実行され、セパレータは表示されません。あなたが見ているものは、以前のビルドからのキャッシュだと思います。プロジェクトを整理して再度ビルドすると、例外が発生します –

+0

@NawedNabiZada影響なし、エラーなし – Wobbles

+0

あなたはその部分を提供しませんでした。そして、ここには縦のセパレータは表示されません。 –

答えて

2

あなたの問題は、あなたのスタイルをすべてのMenuItemsに適用するのではない可能性が高いです。たとえば、あなたが持っていると仮定します。

<Menu> 
    <MenuItem Header="Top item" 
       Background="White"> 
     <MenuItem Header="Sub Menu Item" 
        Background="White" 
        Style="{StaticResource MenuItemStyle1}" /> 
    </MenuItem> 
</Menu> 

このようなレイアウトでは、「サブメニュー項目」で説明した問題が発生します。これは、親アイテムのテンプレートで定義されたポップアップ内に配置され、親アイテムにデフォルトテンプレートがあるためです。

その親項目にも自分のスタイルを持っているので、あなたはそれを変更した場合:

<Menu> 
    <MenuItem Header="Top item" 
       Background="White" 
       Style="{StaticResource MenuItemStyle1}"> 
     <MenuItem Header="Sub Menu Item" 
        Background="White" 
        Style="{StaticResource MenuItemStyle1}" /> 
    </MenuItem> 
</Menu> 

問題が消えます。

+0

これは、行が親コンテナの一部であり、個々のアイテム自体ではないためです。これは、項目ごとに無効にする方法を望んでいたからです。 – Wobbles

+0

はい、階層メニューがある場合、すべての子アイテムは親MenuItemコンテナの内側にあり、この行はそれに属します。 – Evk

+0

bahhh。残念だが少なくとも行動を説明している。 – Wobbles

関連する問題