Working with a WPF application using the MVVM framework.
My window displays the menu and the current ViewModel. In one of the MenuItems, I want to list some of the commands found in the current ViewModel. The commands listed in the menu will vary depending on the ViewModel.
It worked out just fine for me, but the style was messed up - the menu command elements are inside another menu window or something like that. I will attach a screenshot.
I wrapped the ViewModel ICommand objects (RelayCommands, in this case) in the CommandViewModel that displays the Command and Display line that I want in the menu. These CommandViewModels are listed: CurrentWorkspace.AdditionalOptionsCommands .
Here is the XAML for the menu. As I said, it works, it shows the correct elements and the commands are executed. The display is simply incorrect - can someone tell me why and how to fix it? See screenshot.
<Menu> <MenuItem Header="_Additional Options..." ItemsSource="{Binding Path=CurrentWorkspace.AdditionalOptionsCommands}"> <MenuItem.ItemTemplate> <DataTemplate DataType="{x:Type vm:CommandViewModel}"> <MenuItem Header="{Binding Path=DisplayText}" Command="{Binding Path=Command}"/> </DataTemplate> </MenuItem.ItemTemplate> </MenuItem> <MenuItem Header="_Testing"> <MenuItem Header="This looks right" /> <MenuItem Header="This looks right" /> </MenuItem> </Menu>
Current Appearance:

Desired appearance:

source share