菜单项上可见不需要的边框

问题描述 投票:0回答:1

我在网格内有一个菜单,尽管我已将边框厚度和画笔设置为相同的颜色并且为空,但我以某种方式看到右侧白色边框,不确定它来自哪里

我有一个菜单项的示例代码,我没有看到这种情况发生,我的父网格布局可能存在一些问题,但不知道

<Window x:Class="HelloWord.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:HelloWorld"
        mc:Ignorable="d"
        Title="MainWindow" 
        Height="450" 
        Width="800"
        WindowStartupLocation="CenterScreen"
        WindowStyle="None"
        AllowsTransparency="True"
        Background="Transparent">
    <Window.Resources>
        <Style x:Key="Main_MenuItem"
               TargetType="MenuItem">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type MenuItem}">
                        <Border x:Name="border"
                                Height="30"
                                Background="#363435"
                                BorderThickness="0"
                                BorderBrush="{x:Null}"
                                Padding="5">
                            <ContentPresenter ContentSource="Header"
                                               TextBlock.Foreground="White"
                                               HorizontalAlignment="Center"
                                               VerticalAlignment="Center"/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsHighlighted"
                                     Value="True">
                                <Setter Property="Background"
                                        TargetName="border"
                                        Value="#524E4F" />
                                <Setter Property="BorderBrush"
                                        TargetName="border"
                                        Value="#524E4F" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <Border Padding="10" >
        <Grid>
            <Border Background="WhiteSmoke"
                    CornerRadius="5">
                <Border.Effect>
                    <DropShadowEffect Color="#363435" 
                                      ShadowDepth="3" 
                                      Opacity="0.3" />
                </Border.Effect>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="40" />
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <Border Background="#363435"
                            CornerRadius="5,5,0,0">
                        <Border.Effect>
                            <DropShadowEffect ShadowDepth="1" Opacity="0.3" />
                        </Border.Effect>
                    </Border>
                    <StackPanel Orientation="Horizontal">
                        <Menu VerticalAlignment="Center"
                              HorizontalAlignment="Center">
                            <MenuItem Style="{StaticResource Main_MenuItem}" Header="Hello" />
                        </Menu>
                    </StackPanel>
                </Grid>
            </Border>
        </Grid>
    </Border>
</Window>

Window Screenshot

尝试设置边框厚度和画笔,但没有成功

c# wpf xaml
1个回答
0
投票

看看这个:WPF:如何删除 MenuItem 边框

他们有同样的问题,希望这能为您解决。

© www.soinside.com 2019 - 2024. All rights reserved.