TreeView 中的动态上下文菜单与 MVVM
我有一个显示为 TreeView 的 ViewModel 树(使用 HierarchicalDataTemplate)。每个 ViewModel 实例都有可以在其上执行的不同命令,这些命令再次公开为每个项目 ViewModel 的命令 ViewModel 列表。如何创建一个在右键单击的 TreeViewItem 处打开的单个 ContextMenu,并从基础项 ViewModel 的命令 ViewModel 列表中填充其命令?一切都以一种体面的 MVVM 方式进行......
I have a tree of ViewModels displayed as a TreeView (using HierarchicalDataTemplate). Each ViewModel instance has different commands that can be executed on it wich again are exposed as a list of command ViewModels for each item ViewModel. How can I create a single ContextMenu that opens at the TreeViewItem that was rightclicked and that populates its commands from the underlying item ViewModel's command ViewModels list? All in a decent MVVM fashion ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我理解你的问题。我认为你可以像这样构建你的 ViewModel:
然后在 xaml 中
我对分层数据模板没有太多经验,但你可以从上面得到要点。您也可以使用 中的样式执行上述操作,但我面前没有 xaml 编辑器来为您提供正确的语法。
希望有帮助
I think I understand your question. I think that you could structure your ViewModels like this:
and then in xaml
I don't have much experience with hierarchical datatemplate but you get the gist from the above. You could also do the above with a style in the but I don't have a xaml editor in front of me to give you right syntax.
Hope that helps