MVVM 类实例化和参数
我正在尝试让我的大脑进入 MVVM 模式。
我的视图中有一个网格,以及在我的视图模型中操作它并向其添加形状的各种方法。我意识到我应该尽量避免在虚拟机中发生这种情况,所以我将这些方法移到了自己的类中。我想弄清楚的是
a) 应该在哪里创建新类的实例?目前我已经在我的虚拟机中使用了 IoC.Get()
b) NewClass 需要获取视图中的 Grid,我该怎么做? (我唯一能想到的就是让虚拟机获取对其视图的引用,并传递网格 进入 NewClass,但这似乎不是最好的方法)
I'm trying to whip my brain into MVVM mode here.
I have a Grid in my view, and various methods for manipulating it and adding shapes to it in my viewmodel. I realize that I should try to avoid that sort of thing in the VM, so I moved those methods into there own class. What I'm trying to figure out is
a) Where should an instance of the new class be created? Currently I've got it in my VM, using
IoC.Get()
b) The NewClass needs to get a hold of the Grid in the view, how can I do that?
(The only thing I can think of is to have the VM get a reference to its View, and pass the Grid
into the NewClass, but that doesn't seem like the best way to do it)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
A) 如果您需要以无法通过视图模型的方式操作网格,请考虑使用协程。对视图的引用在 ActionExecutionContext 中传递。
A) look at using Coroutines if you need to manipulate the grid in a way you're not able to through the viewmodel. A reference to the view gets passed in the ActionExecutionContext.