Place a dividing line in a menu in WPF Place a dividing line in a menu in WPF wpf wpf

Place a dividing line in a menu in WPF


Use a Separator like this:

<MenuItem Header="_Open" Command="ApplicationCommands.Open" /><Separator /><MenuItem Header="E_xit" Command="ApplicationCommands.Close" />


I needed to iterate through MenuItems for various reasons, and using Separator meant a bit of casting, so I used a 1px high MenuItem instead

<MenuItem Height="1" Background="LightGray"/>

The correct answer most definitely is to use Separator, but the above works visually too, and can be a solution in some cases.