Answer the question
In order to leave comments, you need to log in
How can I change the background of child MenuItems?
In the picture, I managed to make a transparent background for the main menu and for MenuItem, but I don’t know how for the child ones. Help me please.
You need to make it transparent instead of white.
<Menu x:Name="menu" Height="26" VerticalAlignment="Top" Background="{x:Null}" Foreground="{x:Null}">
<MenuItem Header="Настройки" Height="26" Foreground="Lime" RenderTransformOrigin="0.5,0.5" Background="Transparent" BorderBrush="Transparent" Padding="6,0" UseLayoutRounding="False">
<MenuItem Header="Свойства" Foreground="Lime" RenderTransformOrigin="0.5,0.5" Background="Transparent" BorderBrush="Transparent" AutomationProperties.IsColumnHeader="True"/>
<MenuItem Header="О программе" Foreground="Lime" RenderTransformOrigin="0.5,0.5" Background="Transparent" BorderBrush="Transparent" AutomationProperties.IsColumnHeader="True"/>
<Separator/>
<MenuItem Header="Выход" Foreground="Lime" RenderTransformOrigin="0.5,0.5" Background="Transparent" BorderBrush="Transparent" AutomationProperties.IsColumnHeader="True"/>
</MenuItem>
</Menu>
Answer the question
In order to leave comments, you need to log in
You need to redefine the menu element template - just add this code to Window.Resources and that's it, you don't even need to add anything to <Menu>. "MenuItem.TopLevelHeaderTemplateKey" - standard template name
<ControlTemplate x:Key="{x:Static MenuItem.TopLevelHeaderTemplateKey}" TargetType="{x:Type MenuItem}">
<Border Name="Border" >
<Grid>
<ContentPresenter Margin="6,3,6,3" ContentSource="Header" RecognizesAccessKey="True" />
<Popup Name="Popup" Placement="Bottom" IsOpen="{TemplateBinding IsSubmenuOpen}" AllowsTransparency="True" Focusable="False" PopupAnimation="Fade">
<Border Name="SubmenuBorder" SnapsToDevicePixels="True" Background="Transparent">
<StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle" />
</Border>
</Popup>
</Grid>
</Border>
</ControlTemplate>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question