I'm trying to create a dynamic Context Menu in the WPF DataGrid. The following are the issues that I need help:
1) Root Menu Item Header are not bind with ViewModel while the submenu works fine.
2) The submenu always pop up on the left side instead of the right. How can I fix this with style?
<DataGrid.ContextMenu>
<ContextMenu ItemsSource="{Binding PackageCM.Members}" HasDropShadow="True" Placement="Right">
<ContextMenu.ItemContainerStyle>
<Style TargetType="MenuItem">
<Setter Property="Header" Value="{Binding CategoryName}" />
</Style>
</ContextMenu.ItemContainerStyle>
<ContextMenu.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Items}">
<MenuItem Header="{Binding DisplayName}" Command="{Binding AllPackagesVM.OpenCOBAPackageCommand, Source={StaticResource Locator}}"></MenuItem>
</HierarchicalDataTemplate>
</ContextMenu.ItemTemplate>
</ContextMenu>
Root Menu Item Header are not being bind.
Basically, Context Menu is binding to the PackageCM.Members with has a list of Category object and I want to display the CategoryName on the Context Menu root. Following that, Each Category contains a list of Items which will be showed as submenu.
Thanks in advance for help.