WPF 中的动态菜单项
有没有办法在菜单上创建一个部分,以便由 ObservableCollection 之类的内容填充菜单项列表?
我想在 Visual Studio 中复制窗口功能,其中打开的文档选项卡在编号列表中列出,仅限于前 10 个。
Is there a way to create a section on a menu for a list of menu items to be populated by something like an ObservableCollection?
I'd like to replicate the Window functionality in Visual Studio, where the open document tabs are listed in a numbered list, limited to the first 10.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请参阅此处的“合并 ContextMenus”。您可以通过搜索 CompositeCollection 和 menu/ContextMenu 找到更多信息。
编辑:刚刚看到评论中已经提到了 CompositeCollection,但我将把它留在这里以供参考。
See "Merge ContextMenus" from here. You can find more info by searching for CompositeCollection and menu/ContextMenu.
EDIT: Just saw CompositeCollection was already mentioned in a comment, but I'm going to leave this here for reference.
您的菜单现在如何获取数据?是数据绑定吗?查看这篇文章,将您的菜单与集合绑定。
现在由您决定何时添加项目到集合中的逻辑。
例如:在您的场景中,您必须将打开的文档存储在列表中。然后,您必须过滤出前 10 个文档,并将其添加到文章中指定的 MenuItem 类的 Children 属性中。
How does your menu get data right now? Is it databound? Check this article for binding your menu with a collection.
Now it is up to you to add logics when to add item to the collection.
For eg: In your scenario, you have to store the open documents in a list. Then you have to filter out the first 10 documents and add it to the children property of the MenuItem class specified in the article.
您可以在代码中创建菜单项,并在加载表单时手动将它们添加到菜单中。它并不优雅,但它可以完成工作。
You can create menu items in code and manually add them to the menu when the form loads. It isn't elegant, but it gets the job done.