WPF菜单项样式 - 添加边框后标签消失

时间:2015-12-30 11:12:22

标签: wpf xaml menuitem app.xaml

我想在xaml中设置一个menuitem。 menuitem必须有一个虚线边框(仅在右侧) 问题是,当我使用下面的样式时,菜单项标签正在消失。

我有以下Stye:

<Style TargetType="Menu">
    <Setter Property="Background" Value="{StaticResource MainColor_1}"/>
    <Setter Property="Height" Value="40"/>
</Style>
<Style TargetType="MenuItem">
    <Setter Property="Height" Value="40"/>
    <!--<Setter Property="SnapsToDevicePixels" Value="True"/>
    <Setter Property="OverridesDefaultStyle" Value="True"/>-->

    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="MenuItem">
                <Grid Background="{TemplateBinding Background}">
                    <Border Padding="{TemplateBinding Padding}" BorderThickness="0, 0, 3, 0"  Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
                        <Border.BorderBrush>
                            <DrawingBrush Viewport="0,0,8,8" ViewportUnits="Absolute" TileMode="Tile">
                                <DrawingBrush.Drawing>
                                    <DrawingGroup>
                                        <GeometryDrawing Brush="{StaticResource AlternativeColor_1}">
                                            <GeometryDrawing.Geometry>
                                                <GeometryGroup>
                                                    <RectangleGeometry Rect="0,0,50,50" />
                                                    <RectangleGeometry Rect="50,50,50,50" />
                                                </GeometryGroup>
                                            </GeometryDrawing.Geometry>
                                        </GeometryDrawing>
                                    </DrawingGroup>
                                </DrawingBrush.Drawing>
                            </DrawingBrush>
                        </Border.BorderBrush>
                    </Border>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

我该如何解决这个问题?

0 个答案:

没有答案