I've tried to style the ContextMenu
of a customized TextBox
in WPF adding <Setter Property="ContextMenu" Value="{StaticResource ProfessionalContextMenu}" />
to avoid this ugly appearance (the MenuItem
Style is applied globally):
Using this ContextMenu
style:
<Style x:Key="ProfessionalContextMenu" TargetType="{x:Type ContextMenu}">
<Setter Property="Background" Value="Black"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="BorderBrush" Value="#FF494949"/>
<Setter Property="Padding" Value="1"/>
</Style>
But it throws an exception (XamlParseException).
You trying assign Style
to ContextMenu
( <Setter Property="ContextMenu" Value="{StaticResource ProfessionalContextMenu}" />
) and here is the problem probably.
Try using following code:
<TextBox>
<TextBox.ContextMenu>
<ContextMenu Style="{StaticResource ProfessionalContextMenu}">
<MenuItem Header="MenuItem1" />
<MenuItem Header="MenuItem2" />
</ContextMenu>
</TextBox.ContextMenu>
</TextBox>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.