Prism 2 SL:单击按钮时从区域中删除视图 [英] Prism 2 SL : Remove View from Region when button clicked

查看:46
本文介绍了Prism 2 SL:单击按钮时从区域中删除视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Prism 的新手,我正在尝试确定在 Prism 2 应用程序中停用视图的最佳实践——当用户单击视图上的按钮时,我想停用该视图.单击按钮时,视图正在执行命令.

I am new to Prism and I am trying to determine a best practice for deactivating a view in a Prism 2 application -- when a user clicks a button on the view I want to deactivate the view. The view is executing a command when the button is clicked.

视图模型正在接收命令,但视图模型没有对区域管理器的引用.

The view model is receiving the command but the viewmodel does not have a reference to the regionmanager.

视图模型应该知道区域管理器吗?并且即使视图模型有对它的引用,它也需要将视图实例传递给包含区域的 deactive 方法.

Should the view model know about the region manager? And even if the viewmodel had a reference to it, it needs the view instance to pass to the deactive method on the containing region.

我正在为应用程序使用 MVVM 模式.

I am using the MVVM pattern for the app.

推荐答案

我将在这里继续假设您正在使用您所在地区的项目控件或类似控件,因为这是按钮"的最明显用途删除视图".

I'm gonna go on a limb here and assume that you are using an itemscontrol or such for your region, because that's the most obvious use of a "button that removes a view".

在那种情况下,你应该有一个控制器(或任何你想叫它的名字,但棱镜团队似乎使用这种名称来表示这种责任)在某个地方负责管理活动的 ViewModel,或者你使用 DataTemplates 显示您的视图,或者您在添加新实例时手动创建/添加/激活新视图.你的情况似乎是第二个,控制器应该负责管理视图.您的视图模型应该通过依赖注入获得对该控制器的引用,并要求它从活动模型/视图池中删除它.

In that case, you should have a Controller (or whatever you want to call it, but the Prism team seems to use that kind of name for that kind of responsibility) somewhere in charge of managing the active ViewModels, and either you display your views using DataTemplates, or you manually create/add/activate a new view when adding a new instance. Your case seems to be the second one, and the controller should be responsible for managing the views. Your viewmodel should get a reference to that controller through Dependency Injection and ask it to remove it from the pool of active models/views.

Controller 本身接收 IRegionManager 并找到它负责的 Region.

The Controller itself receives the IRegionManager and finds the Region it is responsible for.

我希望这是有道理的,如果没有,请发表评论.

I hope that makes sense, please comment if it does not.

这篇关于Prism 2 SL:单击按钮时从区域中删除视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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