Wpf 如何使用集合在ContextMenu中创建根级菜单项?

Wpf 如何使用集合在ContextMenu中创建根级菜单项?,wpf,contextmenu,itemscontrol,Wpf,Contextmenu,Itemscontrol,我们有一组DesignerLocation对象存储在ViewModel的属性中。我们希望为每个项目创建上下文菜单,以便用户可以轻松访问它们 目前,我们正在将该集合绑定到特定“打开…”上下文菜单的Items属性,这意味着用户必须弹出该菜单,即使只有一个设计器位置 e、 这是一个过于简化的上下文菜单,有三个设计师的位置 Open in... (<-- This menu's Items property is bound to DesignerLocations) Open Desig

我们有一组DesignerLocation对象存储在ViewModel的属性中。我们希望为每个项目创建上下文菜单,以便用户可以轻松访问它们

目前,我们正在将该集合绑定到特定“打开…”上下文菜单的Items属性,这意味着用户必须弹出该菜单,即使只有一个设计器位置

e、 这是一个过于简化的上下文菜单,有三个设计师的位置

Open in... (<-- This menu's Items property is bound to DesignerLocations)
    Open DesignerLocation1
    Open DesignerLocation2
    Open DesignerLocation3
[separator]
Cut
Copy
Paste
这是我们真正想要的

…如果只有一个

Open DesignerLocation1
[separator]
Cut
Copy
Paste
也就是说,如何在不必求助于复合集合或手动响应ContextMenuOpening的情况下实现以下内容

<MenuCollectionPlaceholder>  <-- This would be bound to DesignerLocations and would generate MenuItems as needed without requiring the flyout
[separator]
Cut
Copy
Paste
最后,我看到人们直接在上下文菜单中放置ItemsControl,但我觉得这是错误的,因为ItemsControl本身不是MenuItem。错了吗?那会给我们我们想要的

<ItemsControl>  <-- This would be bound to DesignerLocations and would generate MenuItems as needed without requiring the flyout
[separator]
Cut
Copy
Paste
<MenuCollectionPlaceholder>  <-- This would be bound to DesignerLocations and would generate MenuItems as needed without requiring the flyout
[separator]
Cut
Copy
Paste
<ItemsControl>  <-- This would be bound to DesignerLocations and would generate MenuItems as needed without requiring the flyout
[separator]
Cut
Copy
Paste