[英]How to remove ContextMenu border
所以我试图让按钮出现在我的ListBox
中的右键单击上。
<ListBox Grid.Column="1" Margin="358,44,20,63" Name="scriptbox" Background="#FF282828" Foreground="White" SelectionChanged="Scriptbox_SelectionChanged" BorderThickness="0">
<ListBox.ContextMenu>
<ContextMenu>
<MenuItem
Template="{DynamicResource MenuItemTemplate}"
Header="Delete"
Click="MenuItemDelete_Click" >
</MenuItem>
</ContextMenu>
</ListBox.ContextMenu>
这是我的MenuItem
模板。
<ControlTemplate TargetType="{x:Type MenuItem}" x:Key="MenuItemTemplate">
<Border x:Name="Border" Background="#FF282828" Padding="30,5,30,5" BorderThickness="0" Margin="0">
<ContentPresenter ContentSource="Header" x:Name="HeaderHost" RecognizesAccessKey="True" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsHighlighted" Value="true">
<Setter Property="Background" TargetName="Border" Value="#51544e"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<ItemsPanelTemplate x:Key="MenuItemPanelTemplate">
<StackPanel Margin="-3,0,0,0" Background="White"/>
</ItemsPanelTemplate>
<Style TargetType="{x:Type MenuItem}">
<Setter Property="ItemsPanel" Value="{StaticResource MenuItemPanelTemplate}"/>
</Style>
一切都很好,但按钮周围有白色边框。
您识别为白色边框的是包含您的MenuItem
的ContextMenu
本身。 尝试添加更多按钮并更改ContextMenu
的Background
和BorderBrush
,您会看到。
<ContextMenu Background="Red" BorderBrush="Blue">
像这样改变画笔会导致这个结果,这很明显。
如果您为MenuItems
创建自定义控件模板,您可能也应该为ContextMenu
这样做,如果仅设置画笔不符合您的要求。 正如您在示例中看到的那样,仍然有一条垂直白线是默认控件模板的一部分,您可能希望去掉它。 您可以从这个示例开始,尽管它既不是默认模板也不是完整的。 如果需要,请查看此相关帖子以获取有关如何为ContextMenu
提取默认控件模板的指导。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.