在 Wpf 中创建垂直菜单
如何使用 xaml 在 Visual Studio(在 wpf 中)窗口的左侧创建一个垂直菜单,就像 http://">http:// /www.wpftutorial.net/?我尝试了代码:
<Menu DockPanel.Dock="Left" VerticalAlignment="Top" Background="Gray" BorderBrush="Black">
但它没有完成任务,因为它在顶部呈现了一个水平菜单。
并不一定需要通过控制菜单来完成。如果任何其他具有类似外观的控件是合适的,则可以接受。
How is it possible to create a vertical menu on the left side of the window in Visual Studio (in a wpf) with xaml like the one in http://www.wpftutorial.net/? I try the code:
<Menu DockPanel.Dock="Left" VerticalAlignment="Top" Background="Gray" BorderBrush="Black">
but it does not the task, since it presents a horizontal menu on the top.
It is not required to be done definitely by the control menu. If any other control with similar appearance is appropriate, it is acceptable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当然,只需将
MenuItem.ItemsPanel
更改为使用垂直 StackPanel,而不是默认的水平 StackPanelSure, just change
MenuItem.ItemsPanel
to use a Vertical StackPanel instead of the Default Horizontal one接受的答案很好。但要让侧边栏发挥作用还有很长的路要走。如果您现在需要的是工作菜单,则可以使用此控件。
https://github.com/beto-rodriguez/MaterialMenu
你也可以从 nuget 安装它。
这是一个例子
Accepted anwer is good. But it is a long way to get a good side bar working. you can use this control if what you need is a working menu now.
https://github.com/beto-rodriguez/MaterialMenu
you can install it from nuget too.
here is an example
您可以使用 Style 调整 ItemsPanel(我觉得这更像是 wpf 风格),
VerticalAlignment="Center" 是为了美化目的,您绝对可以跳过它。
然后在菜单代码中
You can adjust the ItemsPanel using Style (which I feel is much more wpf-ish)
the VerticalAlignment="Center" is there for beautification purposes, you can definitely skip it.
then in the menu code
由于某种原因,该解决方案在 ModernWPF 中不适用于我,因此我在垂直 StackPanel 中使用了多个菜单:
For some reason the solution didn't work for me in ModernWPF, so instead I used multiple menus in a vertical StackPanel: