I have a WPF submenu that I want to reuse in a few places in my XAML. It's a collection of eight <MenuItem>
elements with some complicated bindings that I don't want to copy/paste. However, the holder is different in each case: in one place the parent is a <Menu>
, in another place the parent is a <MenuItem>
in a <ContextMenu>
.
I've been experimenting with <Setter Property="Items">
in my <Style>
but I think maybe I'm on the wrong track.
To make it concrete, I'm trying to reduce the code duplication from something like this:
<Menu>
<MenuItem Header="Details" IsCheckable="True" ... />
<MenuItem Header="List" IsCheckable="True" ... />
<MenuItem Header="Thumbnails" IsCheckable="True" ... />
...
</Menu>
...
<ContextMenu>
<MenuItem Header="View">
<MenuItem Header="Details" IsCheckable="True" ... />
<MenuItem Header="List" IsCheckable="True" ... />
<MenuItem Header="Thumbnails" IsCheckable="True" ... />
...
</MenuItem>
</ContextMenu>