【发布时间】:2018-03-22 23:10:28
【问题描述】:
我正在尝试在 WPF DataGrid 中创建一个动态上下文菜单。以下是我需要帮助的问题:
1) 根菜单项标题未与 ViewModel 绑定,而子菜单工作正常。
2) 子菜单总是在左侧而不是右侧弹出。如何用样式解决这个问题?
<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.
基本上,上下文菜单绑定到具有类别对象列表的 PackageCM.Members,我想在上下文菜单根目录上显示 CategoryName。之后,每个类别都包含一个项目列表,这些项目将显示为子菜单。
提前感谢您的帮助。
【问题讨论】:
标签: c# wpf contextmenu submenu