“漂亮"的WPF中使用棱镜和MVVM模式制作模态对话框的方法 [英] The "pretty" way to make a modal dialog in WPF with Prism and MVVM Pattern

查看:369
本文介绍了“漂亮"的WPF中使用棱镜和MVVM模式制作模态对话框的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天,我使用google找到了几种方法,以在带有PRISM 4.1和MVVM模式的WPF中制作令人敬畏的可重用模式对话框.我找到了一些例子,但我必须说其中的一个都不像我喜欢的那样漂亮".

这个: WPF模态对话框(没有mvvm->没用)

>

这非常好:使用MVVM模式时显示对话框(但是它仍然使用的是我自己不需要的自定义ServiceLocator,因为我使用的是IUnity容器.我可以使用逻辑并将其重写为Unity,但这并不是我的诚实观点.

好一会儿,在网上搜索信息后,一些博客(现在找不到源)告诉我,PRISM框架收到了一个称为交互请求"的东西.因此,我检查了Prism文档,并在高级mvvm方案"主题下找到了一小部分,但是文档中提供的信息还不够.

我想知道是否有人有任何好的例子或博客文章,介绍如何使用mvvm在棱镜wpf中实现令人敬畏的模态对话框.

编辑: 关于评论中的问题:

是什么使模态对话框很棒?

确实是个好问题.

  1. 它必须是模态的(对话框打开时,UI的其余部分 应该被冻结)
  2. 对话框视图可以具有自己的视图模型或 至少我想给对话框提供一个对象的实例 查看并将对象返回到父视图
  3. 该视图应该是自己的"xaml"文件
  4. .NET或上的dialogresult功能 至少一种获得响应的方法,该响应是用户在对话框中单击的内容

解决方案

PRISM 5.0提出了显示模态对话框的快速解决方案.使用PopupWindowAction.

<prism:InteractionRequestTrigger SourceObject="{Binding CustomPopupViewRequest, Mode=OneWay}">
    <prism:PopupWindowAction>
        <prism:PopupWindowAction.WindowContent>
            <views:CustomPopupView />
        </prism:PopupWindowAction.WindowContent>
    </prism:PopupWindowAction>
</prism:InteractionRequestTrigger>

yesterday i used google to find a few ways to make an awesome reusable modal dialog in WPF with PRISM 4.1 and the MVVM pattern. I found some examples but i must say non of those were as "pretty" as i liked them to be.

This one: WPF Modal Dialog (no mvvm -> no use)

This is pretty nice: Showing Dialogs when using the MVVM Pattern (but still it's using a selfmade ServiceLocator which i don't need as i am using the IUnity Container. I could use the logic and rewrite it to Unity but that's not the "pretty" way in my honest opinion.

Well after a while searching the web for informations some blog (can't find the source right now) told me that the PRISM Framework got something called "interaction requests". So i checked out the prism documentation and found a small part under the topic "advanced mvvm scenarios" but the information given in the documentation aren't enough.

I'd like to know if somebody have any good example or any good blogpost about how to realize an awesome modal dialog in prism wpf with mvvm.

EDIT: Regarding the question in the comments:

What makes a modal dialog awesome?

Indeed a good question.

  1. It must be modal (while the dialog is open the rest of the UI should be freezed)
  2. The dialog view can have it's own viewmodel or at least i would like to give an instance of an object to the dialog view and return an object back to the parent view
  3. The view should be an own "xaml" file
  4. the dialogresult feature from .NET or at least a way to get a response what the user clicked in the dialog

解决方案

PRISM 5.0 came up with quick solution to show modal dialogs. Using PopupWindowAction.

<prism:InteractionRequestTrigger SourceObject="{Binding CustomPopupViewRequest, Mode=OneWay}">
    <prism:PopupWindowAction>
        <prism:PopupWindowAction.WindowContent>
            <views:CustomPopupView />
        </prism:PopupWindowAction.WindowContent>
    </prism:PopupWindowAction>
</prism:InteractionRequestTrigger>

这篇关于“漂亮"的WPF中使用棱镜和MVVM模式制作模态对话框的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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