WPF Submenu Styling
I can't seem to figure how to get rid of the border in submenus in WPF. More specifically, can't figure out how to get rid of that border.
For minimum repo, create a new WPF application and have this as your MainWindow's xml file::
<Window x:Class="SubmenustyleTest.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:SubmenustyleTest"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<StackPanel>
<Menu>
<MenuItem Header="File">
<MenuItem.ItemContainerStyle>
<Style>
<Setter Property="ItemsControl.Background" Value="LightCoral"/>
<Setter Property="ItemsControl.BorderBrush" Value="OrangeRed"/>
<Setter Property="ItemsControl.Margin" Value="0"/>
</Style>
</MenuItem.ItemContainerStyle>
<MenuItem Header="Open"/>
<MenuItem Header="Save"/>
</MenuItem>
</Menu>
</StackPanel>
</Window>
<Window x:Class="SubmenustyleTest.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:SubmenustyleTest"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<StackPanel>
<Menu>
<MenuItem Header="File">
<MenuItem.ItemContainerStyle>
<Style>
<Setter Property="ItemsControl.Background" Value="LightCoral"/>
<Setter Property="ItemsControl.BorderBrush" Value="OrangeRed"/>
<Setter Property="ItemsControl.Margin" Value="0"/>
</Style>
</MenuItem.ItemContainerStyle>
<MenuItem Header="Open"/>
<MenuItem Header="Save"/>
</MenuItem>
</Menu>
</StackPanel>
</Window>
4 Replies
i'm assuming you've already tried BorderThickness?
Yes. The borderbrush was mainly to see where the border even was.
<Window x:Class="SubmenustyleTest.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:SubmenustyleTest"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<StackPanel>
<Menu>
<MenuItem Header="File">
<MenuItem.ItemContainerStyle>
<Style>
<Setter Property="ItemsControl.Background" Value="LightCoral"/>
<Setter Property="ItemsControl.BorderBrush" Value="OrangeRed"/>
<Setter Property="ItemsControl.BorderThickness" Value="0"/>
<Setter Property="ItemsControl.Margin" Value="0"/>
</Style>
</MenuItem.ItemContainerStyle>
<MenuItem Header="Open"/>
<MenuItem Header="Save"/>
</MenuItem>
</Menu>
</StackPanel>
</Window>
<Window x:Class="SubmenustyleTest.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:SubmenustyleTest"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<StackPanel>
<Menu>
<MenuItem Header="File">
<MenuItem.ItemContainerStyle>
<Style>
<Setter Property="ItemsControl.Background" Value="LightCoral"/>
<Setter Property="ItemsControl.BorderBrush" Value="OrangeRed"/>
<Setter Property="ItemsControl.BorderThickness" Value="0"/>
<Setter Property="ItemsControl.Margin" Value="0"/>
</Style>
</MenuItem.ItemContainerStyle>
<MenuItem Header="Open"/>
<MenuItem Header="Save"/>
</MenuItem>
</Menu>
</StackPanel>
</Window>
As you'd expect, the red parts just disappeared.
But the outside gray part is still there.
Tried styling
Popup
as well since it generates a PopupRoot
. Didn't work either.