C
C#2mo ago
Vir Godem

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>
No description
4 Replies
nullptr
nullptr2mo ago
i'm assuming you've already tried BorderThickness?
Vir Godem
Vir GodemOP2mo ago
Yes. The borderbrush was mainly to see where the border even was.
Vir Godem
Vir GodemOP2mo ago
<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>
With borderthickness as 0.
No description
Vir Godem
Vir GodemOP2mo ago
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.
Want results from more Discord servers?
Add your server