菜单项仅在文本上方突出显示



有人能告诉我为什么我的菜单项是"高亮显示"只有当我悬停在菜单文本上,而不是当我悬停在菜单项的任何地方?这是我的菜单项样式:

            <Style x:Key="CtxMenuItemStyle" TargetType="{x:Type MenuItem}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type MenuItem}">
                        <Border x:Name="Border">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition x:Name="Col0" MinWidth="31" Width="Auto"/>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition x:Name="Col3" Width="20"/>
                                </Grid.ColumnDefinitions>
                                <!-- ContentPresenter to show an Icon if needed -->
                                <ContentPresenter Grid.Column="0" Margin="4,0,6,0" x:Name="Icon" VerticalAlignment="Center" ContentSource="Icon"/>
                                <!-- Glyph is a checkmark if needed for a checkable menu -->
                                <Grid Grid.Column="0" Visibility="Hidden" Margin="4,0,6,0" x:Name="GlyphPanel" VerticalAlignment="Center">
                                    <Path x:Name="GlyphPanelpath" VerticalAlignment="Center" Fill="{TemplateBinding Foreground}" Data="M0,2 L0,4.8 L2.5,7.4 L7.1,2.8 L7.1,0 L2.5,4.6 z" FlowDirection="LeftToRight"/>
                                </Grid>
                                <!-- Content for the menu text etc -->
                                <ContentPresenter Grid.Column="1"
                            Margin="{TemplateBinding Padding}"
                            x:Name="HeaderHost"
                            RecognizesAccessKey="True"
                            ContentSource="Header"/>
                                <!-- The Popup is the body of the menu which expands down or across depending on the level of the item -->
                                <Popup IsOpen="{Binding Path=IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" Placement="Right" x:Name="SubMenuPopup" Focusable="false" PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}">
                                    <Border x:Name="SubMenuBorder" BorderBrush="{Binding Path=Foreground, RelativeSource={RelativeSource AncestorType={x:Type Menu}}}" BorderThickness="1" Padding="2,2,2,2">
                                        <Grid x:Name="SubMenu" Grid.IsSharedSizeScope="True">
                                            <!-- StackPanel holds children of the menu. This is set by IsItemsHost=True -->
                                            <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle"/>
                                        </Grid>
                                    </Border>
                                </Popup>
                            </Grid>
                        </Border>
                        <!-- These triggers re-configure the four arrangements of MenuItem to show different levels of menu via Role -->
                        <ControlTemplate.Triggers>
                            <!-- If no Icon is present the we collapse the Icon Content -->
                            <Trigger Property="Icon" Value="{x:Null}">
                                <Setter Property="Visibility" Value="Hidden" TargetName="Icon"/>
                            </Trigger>
                            <!-- Using the system colors for the Menu Highlight and IsEnabled-->
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="Role" Value="SubmenuItem"/>
                                    <Condition Property="IsHighlighted" Value="true"/>
                                    <Condition Property="IsEnabled" Value="true"/>
                                </MultiTrigger.Conditions>
                                <Setter Property="Foreground" Value="#FF08A5E1"/>
                            </MultiTrigger>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="Role" Value="SubmenuItem"/>
                                    <Condition Property="IsHighlighted" Value="false"/>
                                    <Condition Property="IsEnabled" Value="true"/>
                                </MultiTrigger.Conditions>
                                <Setter Property="Foreground" Value="#FFE1E0E0"/>
                            </MultiTrigger>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Background" Value="Transparent"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

因为您的MenuItem仅对像素进行可测试,它或它的后代实际呈现。你需要给你的外边框添加一个透明背景:

<Border x:Name="Border" Background="Transparent">

相关内容

  • 没有找到相关文章

最新更新