WPF 菜单中的子菜单项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1204230/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
submenu items in WPF Menu
提问by Jobi Joy
how to make SUBMENU ites visible vertical as a left navigation in CODEGURU.COM
如何使 SUBMENU 项目在 CODEGURU.COM 中作为左侧导航垂直可见
In windows we use layoutstyle property to make all main and child items to be viewed vertical and DOCK the menustrip to left.
在 Windows 中,我们使用 layoutstyle 属性使所有主项和子项垂直查看,并将菜单条停靠在左侧。
How to acheive this in WPF
如何在 WPF 中实现这一点
回答by Jobi Joy
For submenus you can add as many MenuItem nested inside.
对于子菜单,您可以添加尽可能多的嵌套在其中的 MenuItem。
<Menu>
<MenuItem Header="File">
<MenuItem Header="Open"/>
<MenuItem Header="Close"/>
</MenuItem>
<MenuItem Header="Edit">
<MenuItem Header="Copy"/>
<MenuItem Header="Paste"/>
</MenuItem>
<MenuItem Header="Options"/>
回答by Pavel Minaev
Just redefine the ItemsPanel
:
只需重新定义ItemsPanel
:
<Menu>
<Menu.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</Menu.ItemsPanel>
<MenuItem Header="Foo"/>
<MenuItem Header="Bar"/>
<MenuItem Header="Baz"/>
...
</Menu>
Note that this will not get rid of the vertical gradient effect in Vista/Win7 menus. If you want that, set Menu.Background
property to whatever you want (could even be Transparent
).
请注意,这不会消除 Vista/Win7 菜单中的垂直渐变效果。如果您愿意,请将Menu.Background
属性设置为您想要的任何内容(甚至可以是Transparent
)。