Have a code like:
<MenuItem ItemSource="SOURCE">
..sub MenuItems
</MenuItem>
How to create the right template that allows to bind the each subitem to the save command.
This is how I did it in a project:
In the Window definition i "define" the commands workspace.
<Window x:Class="WorkForce.Views.MainWindow"
...
xmlns:commands="clr-namespace:WorkForce.Commands"
...
>
After that I connect them to each menu-item.
<MenuItem Header="_File">
<MenuItem Header="_New..." Command="commands:MainWindowCommands.NewFile"/>
<MenuItem Header="_Open..." Command="commands:MainWindowCommands.OpenFile"/>
<MenuItem Header="_Save..." Command="commands:MainWindowCommands.SaveFile"/>
</MenuItem>
I hope that is enough
I saw that you want to add it dynamically. Please look at this: WPF: How can you add a new menuitem to a menu at runtime?
Something like that:
<MenuItem ItemsSource="{Binding SubItems}">
<MenuItem.ItemContainerStyle>
<Style TargetType="MenuItem">
<Setter Property="Command" Value="{Binding SaveCommand}"/>
</Style>
</MenuItem.ItemContainerStyle>
</MenuItem>