How do I create a menu separator bar in WPF using code How do I create a menu separator bar in WPF using code wpf wpf

How do I create a menu separator bar in WPF using code


WPF has a Separator control for just that purpose and it also separates your menu items when the appear on a toolbar. From the MSDN docs:

A Separator control draws a line, horizontal or vertical, between items in controls, such as ListBox, Menu, and ToolBar. Separator controls do not react to any keyboard, mouse, mouse wheel, or tablet input and cannot be enabled or selected.

In code:

using System.Windows.Controls;//Menu myMenu = new Menu();myMenu.Items.Add(new Separator());


In xaml:

<Menu>   <MenuItem Header="Menu Item 1" />   <Separator />   <MenuItem Header="Menu Item 1" /><Menu>