是否有可能将动态生成的上下文菜单注入MVVM视图模型 [英] Is it possible it inject a dynamically generated context menu in to an MVVM view model

查看:163
本文介绍了是否有可能将动态生成的上下文菜单注入MVVM视图模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

有人要求我为另一个视图内的绘图视图用户控件提供解决方案.他们希望能够在此视图中插入上下文菜单,以便可以在其他视图中重用该控件.注入的菜单将 然后将命令发射回注入父对象.更为复杂的是,他们正在使用Caliburm.Micro来支持MVVM,但我很高兴有人可以通过标准绑定解决这个问题.

I've been asked to come up with a solution for a plot view user control which is contained inside another view. They want to be able to inject a context menu in to this view so that the control can be reused in other views. The injected menus would then fire commands back to the injecting parent. The added complexity is that they are using Caliburm.Micro for MVVM support but I'm happy if someone can solve this with standard binding to be honest.

致谢

Celestrium

Celestrium

推荐答案

对于CM应该是可能的,并且IEventAggregator对于从上下文菜单发送的命令来说可能效果很好.上下文菜单本身就是我要开始的服务.

should be possible with CM and IEventAggregator would probably work well for commands sent from the context menu, as for the context menu itself a service would be where I would start. 

使用该服务将其注册到可能需要它的任何视图模型中,然后您就可以为给定的活动项"注入您可能需要的(ioc)菜单项. (已激活的视图模型),该服务将在整个视图模型中使用 可能需要它.另外,您可能会遇到视觉树问题.

With that service its registered with any viewmodel that might need it and you can then inject (ioc) menu items you might need for a given "active item" (activated viewmodel),  this service would be used throughout the viewmodels that might need it.  Also, you might run into visual tree issues.

该服务基本上是一个视图模型本身,它公开菜单文本,命令/操作等.

The service would basically be a viewmodel itself, which exposes menu text, commands / actions etc.


这篇关于是否有可能将动态生成的上下文菜单注入MVVM视图模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆