选中的菜单项中的黑框复选标记 [英] Blackbox checkmark in checked menu item

查看:68
本文介绍了选中的菜单项中的黑框复选标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用具有 IsCheckable=TrueMenuItem 对象时遇到了一个奇怪的问题 - 一张截图值一千字:

这看起来很像

那么,我如何到达那个黑匣子,并让它成为,比如说,GhostWhite?

解决方案

为我工作.

按照您引用的链接中的说明导出模板.

将该样式应用到 MneuItems.

<按钮内容="一个"/><按钮内容="两个"/><菜单><MenuItem Header="Markets" Style="{DynamicResource MenuItemStyle1}"><MenuItem IsCheckable="True" Header="British" Style="{DynamicResource MenuItemStyle1}"/><MenuItem IsCheckable="True" Header="Irish" Style="{DynamicResource MenuItemStyle1}"/></菜单项></菜单></工具栏>

将模板中的 Background 更改为 Yellow 如下:

<Border x:Name="GlyphPanel" BorderBrush="#80DADADA" BorderThickness="1" Background="Yellow" Height="20" Margin="0,1" Visibility="Hidden" Width="20">

为了让这个例子完整,下面是我导出的模板:

<Style x:Key="MenuItemStyle1" TargetType="{x:Type MenuItem}"><Setter Property="OverridesDefaultStyle" Value="True"/><Setter Property="Horizo​​ntalContentAlignment" Value="{Binding Horizo​​ntalContentAlignment, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type ItemsControl}}}"/><Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type ItemsControl}}}"/><Setter Property="Background" Value="透明"/><Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.MenuTextBrushKey}}"/><Setter Property="BorderThickness" Value="1"/><Setter Property="Margin" Value="0,1,0,0"/><Setter Property="Padding" Value="8,3"/><Setter Property="DockPanel.Dock" Value="Top"/><Setter Property="ScrollViewer.PanningMode" Value="Both"/><Setter Property="Stylus.IsFlicksEnabled" Value="False"/><Setter 属性="模板"><Setter.Value><ControlTemplate TargetType="{x:Type MenuItem}"><网格背景="透明" SnapsToDevicePixels="True"><Grid.ColumnDefinitions><ColumnDefinition MinWidth="24" SharedSizeGroup="MenuItemIconColumnGroup" Width="Auto"/><ColumnDefinition Width="*"/><ColumnDefinition SharedSizeGroup="MenuItemIGTColumnGroup" Width="Auto"/><ColumnDefinition Width="14"/></Grid.ColumnDefinitions><Border x:Name="Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.ColumnSpan="4" Margin="1,0"/>;<ContentPresenter x:Name="Icon" Content="{TemplateBinding Icon}" ContentSource="Icon" Margin="0" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center"/><Border x:Name="GlyphPanel" BorderBrush="#80DADADA" BorderThickness="1" Background="Yellow" Height="20" Margin="0,1" Visibility="Hidden" Width="20"><Path Data="M0,2.5L2.5,5 7,0.5" FlowDirection="LeftToRight" Horizo​​ntalAlignment="Center" Stroke="{TemplateBinding Foreground}" StrokeThickness="1.2" VerticalAlignment="Center"/></边框><ContentPresenter ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" Grid.Column="1" ContentStringFormat="{TemplateBinding HeaderStringFormat}" ContentSource="Header" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/><TextBlock Grid.Column="2" Horizo​​ntalAlignment="Right" Margin="4,3,2,3" Text="{TemplateBinding InputGestureText}"/></网格><ControlTemplate.Triggers><Trigger Property="Icon" Value="{x:Null}"><Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/></触发器><Trigger Property="IsChecked" Value="True"><Setter Property="Visibility" TargetName="GlyphPanel" Value="Visible"/><Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/></触发器><Trigger Property="IsHighlighted" Value="True"><Setter Property="BorderBrush" TargetName="Border" Value="#80DADADA"/><Setter Property="Background" TargetName="Border" Value="#210080FF"/><Setter Property="BorderBrush" TargetName="GlyphPanel" Value="#90006CD9"/><Setter Property="Background" TargetName="GlyphPanel" Value="#FFEEF5FD"/></触发器><Trigger Property="IsEnabled" Value="False"><Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/></触发器></ControlTemplate.Triggers></控制模板></Setter.Value></Setter><Style.Triggers><Trigger Property="Role" Value="TopLevelHeader"><Setter Property="Padding" Value="6,2,7,2"/><Setter Property="Grid.IsSharedSizeScope" Value="True"/><Setter 属性="模板"><Setter.Value><ControlTemplate TargetType="{x:Type MenuItem}"><Border x:Name="Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1" Background="{TemplateBinding Background}" SnapsToDevicePixels="True"><DockPanel x:Name="Header"><ContentPresenter x:Name="Icon" Content="{TemplateBinding Icon}" ContentSource="Icon" Margin="4,0,6,0" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center"/><Path x:Name="GlyphPanel" Data="M0,2.5L2.5,5 7,0.5" FlowDirection="LeftToRight" Margin="4,0,6,0" Stroke="{TemplateBinding Foreground}" StrokeThickness="1.2" Visibility="Collapsed" VerticalAlignment="Center"/><ContentPresenter ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" ContentStringFormat="{TemplateBinding HeaderStringFormat}" ContentSource="Header" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBindingSnapsToDevicePixels}"/><Popup x:Name="PART_Popup" AllowsTransparency="True" Focusable="False" Horizo​​ntalOffset="-1" IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:StaticSystemParameters.MenuPopupAnimationKey}}" Placement="Bottom"><Themes:SystemDropShadowChrome x:Name="Shdw" Color="Transparent"><Border x:Name="SubMenuBorder" BorderBrush="#FFB6BDC5" BorderThickness="1" Background="#FFEEF5FD"><网格><矩形填充="#FFEEF5FD" Horizo​​ntalAlignment="Left" Height="1" Margin="0,-1,0,0" VerticalAlignment="Top" Width="{Binding ActualWidth, ElementName=Header}"/><ScrollViewer x:Name="SubMenuScrollViewer" Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}"><Grid RenderOptions.ClearTypeHint="Enabled" Grid.IsSharedSizeScope="True"><Grid.ColumnDefinitions><ColumnDefinition MinWidth="24" SharedSizeGroup="MenuItemIconColumnGroup" Width="Auto"/><ColumnDefinition Width="*"/></Grid.ColumnDefinitions><Canvas Horizo​​ntalAlignment="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}"/></画布><矩形填充="#FFEEF5FD" Margin="0,1"/><ItemsPresenter x:Name="ItemsPresenter" Grid.ColumnSpan="2" KeyboardNavigation.DirectionalNavigation="Cycle" Margin="0,0,0,1" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" KeyboardNavigation.TabNavigation="Cycle"/></网格></ScrollViewer></网格></边框></Themes:SystemDropShadowChrome></弹出窗口></DockPanel></边框><ControlTemplate.Triggers><Trigger Property="IsSuspendingPopupAnimation" Value="True"><Setter Property="PopupAnimation" TargetName="PART_Popup" Value="None"/></触发器><Trigger Property="Icon" Value="{x:Null}"><Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/></触发器><Trigger Property="IsChecked" Value="True"><Setter Property="Visibility" TargetName="GlyphPanel" Value="Visible"/><Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/></触发器><Trigger Property="IsHighlighted" Value="True"><Setter Property="BorderBrush" TargetName="Border" Value="#80DADADA"/><Setter Property="Background" TargetName="Border" Value="#210080FF"/></触发器><Trigger Property="IsSubmenuOpen" Value="True"><Setter Property="BorderBrush" TargetName="Border" Value="#FFB6BDC5"/><Setter Property="Background" TargetName="Border" Value="#FFEEF5FD"/></触发器><Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="True"><Setter Property="Margin" TargetName="Shdw" Value="0,0,5,5"/><Setter Property="SnapsToDevicePixels" TargetName="Shdw" Value="True"/><Setter Property="Color" TargetName="Shdw" Value="#71000000"/></触发器><Trigger Property="IsEnabled" Value="False"><Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/></触发器><Trigger Property="CanContentScroll" SourceName="SubMenuScrollViewer" Value="False"><Setter Property="Canvas.Top" TargetName="OpaqueRect" Value="{Binding VerticalOffset, ElementName=SubMenuScrollViewer}"/><Setter Property="Canvas.Left" TargetName="OpaqueRect" Value="{Binding Horizo​​ntalOffset, ElementName=SubMenuScrollViewer}"/></触发器></ControlTemplate.Triggers></控制模板></Setter.Value></Setter></触发器><Trigger Property="Role" Value="TopLevelItem"><Setter Property="Margin" Value="0,1"/><Setter Property="Padding" Value="7,1,8,2"/><Setter 属性="模板"><Setter.Value><ControlTemplate TargetType="{x:Type MenuItem}"><Border x:Name="Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1" Background="{TemplateBinding Background}" SnapsToDevicePixels="True"><DockPanel><ContentPresenter x:Name="Icon" Content="{TemplateBinding Icon}" ContentSource="Icon" Margin="4,0,6,0" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center"/><Path x:Name="GlyphPanel" Data="M0,2.5L2.5,5 7,0.5" FlowDirection="LeftToRight" Margin="4,0,6,0" Stroke="{TemplateBinding Foreground}" StrokeThickness="1.2" Visibility="Collapsed" VerticalAlignment="Center"/><ContentPresenter ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" ContentStringFormat="{TemplateBinding HeaderStringFormat}" ContentSource="Header" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBindingSnapsToDevicePixels}"/></DockPanel></边框><ControlTemplate.Triggers><Trigger Property="Icon" Value="{x:Null}"><Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/></触发器><Trigger Property="IsChecked" Value="True"><Setter Property="Visibility" TargetName="GlyphPanel" Value="Visible"/><Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/></触发器><Trigger Property="IsHighlighted" Value="True"><Setter Property="BorderBrush" TargetName="Border" Value="#80DADADA"/><Setter Property="Background" TargetName="Border" Value="#210080FF"/></触发器><Trigger Property="IsEnabled" Value="False"><Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/></触发器></ControlTemplate.Triggers></控制模板></Setter.Value></Setter></触发器><Trigger Property="Role" Value="SubmenuHeader"><Setter Property="DockPanel.Dock" Value="Top"/><Setter Property="Padding" Value="8,3"/><Setter Property="Grid.IsSharedSizeScope" Value="True"/><Setter 属性="模板"><Setter.Value><ControlTemplate TargetType="{x:Type MenuItem}"><网格背景="透明" SnapsToDevicePixels="True"><Grid.ColumnDefinitions><ColumnDefinition MinWidth="24" SharedSizeGroup="MenuItemIconColumnGroup" Width="Auto"/><ColumnDefinition Width="*"/><ColumnDefinition SharedSizeGroup="MenuItemIGTColumnGroup" Width="Auto"/><ColumnDefinition Width="14"/></Grid.ColumnDefinitions><Border x:Name="Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.ColumnSpan="4" Margin="1,0"/><ContentPresenter x:Name="Icon" Content="{TemplateBinding Icon}" ContentSource="Icon" Margin="3" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center"/><Border x:Name="GlyphPanel" BorderBrush="#80DADADA" BorderThickness="1" Background="#FF212121" Height="20" Margin="0,1" Visibility="Hidden" Width="20">;<Path Data="M0,2.5L2.5,5 7,0.5" FlowDirection="LeftToRight" Horizo​​ntalAlignment="Center" Stroke="{TemplateBinding Foreground}" StrokeThickness="1.2" VerticalAlignment="Center"/></边框><ContentPresenter ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" Grid.Column="1" ContentStringFormat="{TemplateBinding HeaderStringFormat}" ContentSource="Header" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/><Path Grid.Column="3" DockPanel.Dock="Right" Data="M0,0L4,3.5 0,7z" Fill="{TemplateBinding Foreground}" Margin="4,0,6,0" VerticalAlignment=中心"/><Popup x:Name="PART_Popup" AllowsTransparency="True" Focusable="False" IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}"放置=右"><Themes:SystemDropShadowChrome x:Name="Shdw" Color="Transparent"><Border x:Name="SubMenuBorder" BorderBrush="#FFB6BDC5" BorderThickness="1" Background="#FFEEF5FD" Grid.IsSharedSizeScope="True"><ScrollViewer x:Name="SubMenuScrollViewer" Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}"><Grid RenderOptions.ClearTypeHint="已启用"><Grid.ColumnDefinitions><ColumnDefinition MinWidth="24" SharedSizeGroup="MenuItemIconColumnGroup" Width="Auto"/><ColumnDefinition Width="*"/></Grid.ColumnDefinitions><Canvas Horizo​​ntalAlignment="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}"/></画布><矩形填充="#FFEEF5FD" Margin="0,1"/><ItemsPresenter x:Name="ItemsPresenter" Grid.ColumnSpan="2" KeyboardNavigation.DirectionalNavigation="Cycle" Margin="0,0,0,1" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" KeyboardNavigation.TabNavigation="Cycle"/></网格></ScrollViewer></边框></Themes:SystemDropShadowChrome></弹出窗口></网格><ControlTemplate.Triggers><Trigger Property="IsSuspendingPopupAnimation" Value="True"><Setter Property="PopupAnimation" TargetName="PART_Popup" Value="None"/></触发器><Trigger Property="Icon" Value="{x:Null}"><Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/></触发器><Trigger Property="IsChecked" Value="True"><Setter Property="Visibility" TargetName="GlyphPanel" Value="Visible"/><Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/></触发器><Trigger Property="IsHighlighted" Value="True"><Setter Property="BorderBrush" TargetName="Border" Value="#80DADADA"/><Setter Property="Background" TargetName="Border" Value="#210080FF"/><Setter Property="BorderBrush" TargetName="GlyphPanel" Value="#90006CD9"/><Setter Property="Background" TargetName="GlyphPanel" Value="#FFEEF5FD"/></触发器><Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="True"><Setter Property="Margin" TargetName="Shdw" Value="0,0,5,5"/><Setter Property="SnapsToDevicePixels" TargetName="Shdw" Value="True"/><Setter Property="Color" TargetName="Shdw" Value="#71000000"/></触发器><Trigger Property="IsEnabled" Value="False"><Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/></触发器><Trigger Property="CanContentScroll" SourceName="SubMenuScrollViewer" Value="False"><Setter Property="Canvas.Top" TargetName="OpaqueRect" Value="{Binding VerticalOffset, ElementName=SubMenuScrollViewer}"/><Setter Property="Canvas.Left" TargetName="OpaqueRect" Value="{Binding Horizo​​ntalOffset, ElementName=SubMenuScrollViewer}"/></触发器></ControlTemplate.Triggers></控制模板></Setter.Value></Setter></触发器></Style.Triggers></风格></Window.Resources>

I'm having a weird problem with MenuItem objects that have IsCheckable=True - a screenshot is worth a thousand words:

This looks very much like Check Mark Showing as a Black Box in Menu, except the accepted answer there, unless I misread it badly, suggests to tweak ToolBar.MenuStyleKey, which doesn't seem to be tweaking the right thing at all:

<Style x:Key="{x:Static ToolBar.MenuStyleKey}" TargetType="Menu">
    <Setter Property="Background" Value="Yellow" />
</Style>

So, how do I get to that black box, and make it, say, GhostWhite?

解决方案

Works for me.

Exported the template per the instructions in the link you referenced.

Applied that style to the MneuItems.

<ToolBar>
    <Button Content="One"/>
    <Button Content="Two"/>
    <Menu>
        <MenuItem Header="Markets" Style="{DynamicResource MenuItemStyle1}">
            <MenuItem IsCheckable="True" Header="British" Style="{DynamicResource MenuItemStyle1}"/>
            <MenuItem IsCheckable="True" Header="Irish" Style="{DynamicResource MenuItemStyle1}"/>
        </MenuItem>
    </Menu>
</ToolBar>

Changed Background to Yellow in the template as such:

<Border x:Name="GlyphPanel" BorderBrush="#80DADADA" BorderThickness="1" Background="Yellow" Height="20" Margin="0,1" Visibility="Hidden" Width="20">

Just to make this example totally complete, below is the template that I exported:

<Window.Resources>
    <Style x:Key="MenuItemStyle1" TargetType="{x:Type MenuItem}">
        <Setter Property="OverridesDefaultStyle" Value="True"/>
        <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type ItemsControl}}}"/>
        <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type ItemsControl}}}"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.MenuTextBrushKey}}"/>
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="Margin" Value="0,1,0,0"/>
        <Setter Property="Padding" Value="8,3"/>
        <Setter Property="DockPanel.Dock" Value="Top"/>
        <Setter Property="ScrollViewer.PanningMode" Value="Both"/>
        <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type MenuItem}">
                    <Grid Background="Transparent" SnapsToDevicePixels="True">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition MinWidth="24" SharedSizeGroup="MenuItemIconColumnGroup" Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition SharedSizeGroup="MenuItemIGTColumnGroup" Width="Auto"/>
                            <ColumnDefinition Width="14"/>
                        </Grid.ColumnDefinitions>
                        <Border x:Name="Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.ColumnSpan="4" Margin="1,0"/>
                        <ContentPresenter x:Name="Icon" Content="{TemplateBinding Icon}" ContentSource="Icon" Margin="0" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center"/>
                        <Border x:Name="GlyphPanel" BorderBrush="#80DADADA" BorderThickness="1" Background="Yellow" Height="20" Margin="0,1" Visibility="Hidden" Width="20">
                            <Path Data="M0,2.5L2.5,5 7,0.5" FlowDirection="LeftToRight" HorizontalAlignment="Center" Stroke="{TemplateBinding Foreground}" StrokeThickness="1.2" VerticalAlignment="Center"/>
                        </Border>
                        <ContentPresenter ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" Grid.Column="1" ContentStringFormat="{TemplateBinding HeaderStringFormat}" ContentSource="Header" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                        <TextBlock Grid.Column="2" HorizontalAlignment="Right" Margin="4,3,2,3" Text="{TemplateBinding InputGestureText}"/>
                    </Grid>
                    <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="BorderBrush" TargetName="Border" Value="#80DADADA"/>
                            <Setter Property="Background" TargetName="Border" Value="#210080FF"/>
                            <Setter Property="BorderBrush" TargetName="GlyphPanel" Value="#90006CD9"/>
                            <Setter Property="Background" TargetName="GlyphPanel" Value="#FFEEF5FD"/>
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="Role" Value="TopLevelHeader">
                <Setter Property="Padding" Value="6,2,7,2"/>
                <Setter Property="Grid.IsSharedSizeScope" Value="True"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type MenuItem}">
                            <Border x:Name="Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
                                <DockPanel x:Name="Header">
                                    <ContentPresenter x:Name="Icon" Content="{TemplateBinding Icon}" ContentSource="Icon" Margin="4,0,6,0" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center"/>
                                    <Path x:Name="GlyphPanel" Data="M0,2.5L2.5,5 7,0.5" FlowDirection="LeftToRight" Margin="4,0,6,0" Stroke="{TemplateBinding Foreground}" StrokeThickness="1.2" Visibility="Collapsed" VerticalAlignment="Center"/>
                                    <ContentPresenter ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" ContentStringFormat="{TemplateBinding HeaderStringFormat}" ContentSource="Header" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                                    <Popup x:Name="PART_Popup" AllowsTransparency="True" Focusable="False" HorizontalOffset="-1" IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}" Placement="Bottom">
                                        <Themes:SystemDropShadowChrome x:Name="Shdw" Color="Transparent">
                                            <Border x:Name="SubMenuBorder" BorderBrush="#FFB6BDC5" BorderThickness="1" Background="#FFEEF5FD">
                                                <Grid>
                                                    <Rectangle Fill="#FFEEF5FD" HorizontalAlignment="Left" Height="1" Margin="0,-1,0,0" VerticalAlignment="Top" Width="{Binding ActualWidth, ElementName=Header}"/>
                                                    <ScrollViewer x:Name="SubMenuScrollViewer" Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}">
                                                        <Grid RenderOptions.ClearTypeHint="Enabled" Grid.IsSharedSizeScope="True">
                                                            <Grid.ColumnDefinitions>
                                                                <ColumnDefinition MinWidth="24" SharedSizeGroup="MenuItemIconColumnGroup" Width="Auto"/>
                                                                <ColumnDefinition Width="*"/>
                                                            </Grid.ColumnDefinitions>
                                                            <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 Fill="#FFEEF5FD" Margin="0,1"/>
                                                            <ItemsPresenter x:Name="ItemsPresenter" Grid.ColumnSpan="2" KeyboardNavigation.DirectionalNavigation="Cycle" Margin="0,0,0,1" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" KeyboardNavigation.TabNavigation="Cycle"/>
                                                        </Grid>
                                                    </ScrollViewer>
                                                </Grid>
                                            </Border>
                                        </Themes:SystemDropShadowChrome>
                                    </Popup>
                                </DockPanel>
                            </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="BorderBrush" TargetName="Border" Value="#80DADADA"/>
                                    <Setter Property="Background" TargetName="Border" Value="#210080FF"/>
                                </Trigger>
                                <Trigger Property="IsSubmenuOpen" Value="True">
                                    <Setter Property="BorderBrush" TargetName="Border" Value="#FFB6BDC5"/>
                                    <Setter Property="Background" TargetName="Border" Value="#FFEEF5FD"/>
                                </Trigger>
                                <Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="True">
                                    <Setter Property="Margin" TargetName="Shdw" Value="0,0,5,5"/>
                                    <Setter Property="SnapsToDevicePixels" TargetName="Shdw" Value="True"/>
                                    <Setter Property="Color" TargetName="Shdw" Value="#71000000"/>
                                </Trigger>
                                <Trigger Property="IsEnabled" Value="False">
                                    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                                </Trigger>
                                <Trigger Property="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>
                    </Setter.Value>
                </Setter>
            </Trigger>
            <Trigger Property="Role" Value="TopLevelItem">
                <Setter Property="Margin" Value="0,1"/>
                <Setter Property="Padding" Value="7,1,8,2"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type MenuItem}">
                            <Border x:Name="Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
                                <DockPanel>
                                    <ContentPresenter x:Name="Icon" Content="{TemplateBinding Icon}" ContentSource="Icon" Margin="4,0,6,0" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center"/>
                                    <Path x:Name="GlyphPanel" Data="M0,2.5L2.5,5 7,0.5" FlowDirection="LeftToRight" Margin="4,0,6,0" Stroke="{TemplateBinding Foreground}" StrokeThickness="1.2" Visibility="Collapsed" VerticalAlignment="Center"/>
                                    <ContentPresenter ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" ContentStringFormat="{TemplateBinding HeaderStringFormat}" ContentSource="Header" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                                </DockPanel>
                            </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="BorderBrush" TargetName="Border" Value="#80DADADA"/>
                                    <Setter Property="Background" TargetName="Border" Value="#210080FF"/>
                                </Trigger>
                                <Trigger Property="IsEnabled" Value="False">
                                    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Trigger>
            <Trigger Property="Role" Value="SubmenuHeader">
                <Setter Property="DockPanel.Dock" Value="Top"/>
                <Setter Property="Padding" Value="8,3"/>
                <Setter Property="Grid.IsSharedSizeScope" Value="True"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type MenuItem}">
                            <Grid Background="Transparent" SnapsToDevicePixels="True">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition MinWidth="24" SharedSizeGroup="MenuItemIconColumnGroup" Width="Auto"/>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition SharedSizeGroup="MenuItemIGTColumnGroup" Width="Auto"/>
                                    <ColumnDefinition Width="14"/>
                                </Grid.ColumnDefinitions>
                                <Border x:Name="Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.ColumnSpan="4" Margin="1,0"/>
                                <ContentPresenter x:Name="Icon" Content="{TemplateBinding Icon}" ContentSource="Icon" Margin="3" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center"/>
                                <Border x:Name="GlyphPanel" BorderBrush="#80DADADA" BorderThickness="1" Background="#FF212121" Height="20" Margin="0,1" Visibility="Hidden" Width="20">
                                    <Path Data="M0,2.5L2.5,5 7,0.5" FlowDirection="LeftToRight" HorizontalAlignment="Center" Stroke="{TemplateBinding Foreground}" StrokeThickness="1.2" VerticalAlignment="Center"/>
                                </Border>
                                <ContentPresenter ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" Grid.Column="1" ContentStringFormat="{TemplateBinding HeaderStringFormat}" ContentSource="Header" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                                <Path Grid.Column="3" DockPanel.Dock="Right" Data="M0,0L4,3.5 0,7z" Fill="{TemplateBinding Foreground}" Margin="4,0,6,0" VerticalAlignment="Center"/>
                                <Popup x:Name="PART_Popup" AllowsTransparency="True" Focusable="False" IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}" Placement="Right">
                                    <Themes:SystemDropShadowChrome x:Name="Shdw" Color="Transparent">
                                        <Border x:Name="SubMenuBorder" BorderBrush="#FFB6BDC5" BorderThickness="1" Background="#FFEEF5FD" Grid.IsSharedSizeScope="True">
                                            <ScrollViewer x:Name="SubMenuScrollViewer" Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}">
                                                <Grid RenderOptions.ClearTypeHint="Enabled">
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition MinWidth="24" SharedSizeGroup="MenuItemIconColumnGroup" Width="Auto"/>
                                                        <ColumnDefinition Width="*"/>
                                                    </Grid.ColumnDefinitions>
                                                    <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 Fill="#FFEEF5FD" Margin="0,1"/>
                                                    <ItemsPresenter x:Name="ItemsPresenter" Grid.ColumnSpan="2" KeyboardNavigation.DirectionalNavigation="Cycle" Margin="0,0,0,1" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" KeyboardNavigation.TabNavigation="Cycle"/>
                                                </Grid>
                                            </ScrollViewer>
                                        </Border>
                                    </Themes:SystemDropShadowChrome>
                                </Popup>
                            </Grid>
                            <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="BorderBrush" TargetName="Border" Value="#80DADADA"/>
                                    <Setter Property="Background" TargetName="Border" Value="#210080FF"/>
                                    <Setter Property="BorderBrush" TargetName="GlyphPanel" Value="#90006CD9"/>
                                    <Setter Property="Background" TargetName="GlyphPanel" Value="#FFEEF5FD"/>
                                </Trigger>
                                <Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="True">
                                    <Setter Property="Margin" TargetName="Shdw" Value="0,0,5,5"/>
                                    <Setter Property="SnapsToDevicePixels" TargetName="Shdw" Value="True"/>
                                    <Setter Property="Color" TargetName="Shdw" Value="#71000000"/>
                                </Trigger>
                                <Trigger Property="IsEnabled" Value="False">
                                    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                                </Trigger>
                                <Trigger Property="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>
                    </Setter.Value>
                </Setter>
            </Trigger>
        </Style.Triggers>
    </Style>
</Window.Resources>

这篇关于选中的菜单项中的黑框复选标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆