WPF上下文菜单自定义样式问题

时间:2013-12-03 19:15:58

标签: c# .net wpf xaml custom-controls

我正在尝试在WPF中自定义上下文菜单,我可以通过在MSDN上关注this示例来实现它。 Jigsaw中的最后一块是子菜单标题颜色(Submenu标题)。

如果您注意到两个子菜单在鼠标悬停时都有白色,但子菜单标题采用子菜单项(项目1,项目等)的正常颜色,即使它突出显示。

我需要做些什么才能更改其突出显示的鼠标悬停颜色。

<ControlTemplate x:Key="{x:Static MenuItem.SubmenuHeaderTemplateKey}" TargetType="{x:Type MenuItem}">
    <Border x:Name="Border" BorderThickness="1">
        <Grid Height="22">
            <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" SharedSizeGroup="Icon" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto" SharedSizeGroup="Shortcut" />
            <ColumnDefinition Width="13" />
            </Grid.ColumnDefinitions>
            <ContentPresenter x:Name="Icon" Margin="6,0,6,0" VerticalAlignment="Center" ContentSource="Icon"/>
            <ContentPresenter x:Name="HeaderHost" Margin="3,0,3,0" Grid.Column="1" VerticalAlignment="Center" ContentSource="Header" RecognizesAccessKey="True" TextOptions.TextFormattingMode="Display" />
            <Path x:Name="RightArrow" Grid.Column="3" HorizontalAlignment="Center" VerticalAlignment="Center" Data="M 0 0 L 0 7 L 4 3.5 Z" Fill="#49a3e1" />
            <Popup x:Name="Popup" Placement="Right" HorizontalOffset="-4" IsOpen="{TemplateBinding IsSubmenuOpen}" AllowsTransparency="True" Focusable="False" PopupAnimation="Fade">
            <Border x:Name="SubmenuBorder" SnapsToDevicePixels="True" Background="White" BorderThickness="1" BorderBrush="#49a3e1">
                <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle"/>
            </Border>
            </Popup>
        </Grid>
    </Border>
    <ControlTemplate.Triggers>
        <Trigger Property="Icon" Value="{x:Null}">
            <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
        </Trigger>
        <Trigger Property="IsHighlighted" Value="true">
            <Setter Property="Background" TargetName="Border" Value="#49a3e1"/>
            <Setter Property="Fill" TargetName="RightArrow" Value="White"/>
            <Setter Property="Foreground" Value="White"/>
        </Trigger>
        <Trigger Property="IsHighlighted" Value="false">
            <Setter Property="Foreground" Value="Red"/>
        </Trigger>
        <Trigger SourceName="Popup" Property="AllowsTransparency" Value="True">
            <Setter TargetName="SubmenuBorder" Property="Padding" Value="3" />
            <Setter Property="Foreground" Value="Black"/>
        </Trigger>
        <Trigger Property="IsEnabled" Value="false">
            <Setter Property="Foreground" Value="Pink"/>
        </Trigger>
    </ControlTemplate.Triggers>
    </ControlTemplate>

enter image description here

0 个答案:

没有答案