设置 MenuItem 子菜单高度的最佳方法?
我目前有一个菜单项(上下文菜单的一部分),大约有 35 个菜单项。正因为如此,它导致子菜单巨大。尽管我有滚动能力,但我想设置该子菜单的高度,同时仍具有滚动能力。
我弄乱了 MenuItem.Itemspanel,但无法设置子菜单的高度并仍然滚动。
I currently have a menuitem (part of a context menu), with about ~35 menu items. Because of this, it causes the sub-menu to be huge. Even though I have scrolling ability, I would like to set the height of this submenu while having the ability to still scroll.
I've messed w/ the MenuItem.Itemspanel but have not been able to set the sub-menu's height and still scroll.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,WPF 不允许通过属性对其进行修改。您必须修改默认的 ControlTemplate。
编辑:
我在此处修改了博客条目
这是一个示例(请注意在“SubMenuScrollViewer”上添加了“MaxHeight”):
这只是为了覆盖 Aero 主题。正如您所看到的,MenuItem 有很多 XAML,因此它并不优雅。只需创建一个单独的 ResourceDictionary 即可保持整洁。
Unfortunately, WPF does not allow this to be modified by properties. You will have to modify the default ControlTemplate.
EDIT:
I revised the blog entry on that here
Here is a sample (notice the addition of "MaxHeight" on "SubMenuScrollViewer"):
This is just to override the Aero theme. As you can see there is a lot of XAML for the MenuItem, so it's not graceful. Just make a separate ResourceDictionary to keep things tidy.