the way you're using the MenuItem
control is wrong, it is meant to be hosted inside the Menu
control or another MenuItem
.
As for the solution to your problem, there are two. the first one is to write a custom control that reuses the ContextMenu
to host the menu items, you will write something like this:
<m:SplitButton Content="Split Button" Placement="Bottom">
<MenuItem Header="MenuItem 1"/>
<MenuItem Header="MenuItem 2">
<MenuItem Header="MenuItem 1"/>
<MenuItem Header="MenuItem 2"/>
</MenuItem>
</m:SplitButton
http://www.codeproject.com/Articles/20612/A-WPF-SplitButton
the second approach is to host the Menu
control inside the DropDownContent
and re-style everything, there will be a lot of xaml markup.
the Menu
control will be easy to re-style, the only thing you need to do is make sure that menu items are displayed vertically instead of horizontally, using the following markup:
<Style TargetType="Menu">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" IsItemsHost="True" />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</Style>
the hardest part is styling the MenuItems
, they are styled based on their Role
property. It can have four possible values:
- TopLevelHeader : direct child of
Menu
with sub-menu items. - TopLevelItem : direct child of
Menu
without sub-menu items. - SubmenuHeader : direct child of
MenuItem
with sub-menu items. - SubmenuItem : direct child of
MenuItem
without sub-menu items.
Regards