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

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

问题描述

昨天我使用谷歌找到了一些方法来使用 PRISM 4.1 和 MVVM 模式在 WPF 中制作一个很棒的可重用模态对话框.我找到了一些例子,但我必须说没有一个像我喜欢的那样漂亮".

这个:WPF Modal Dialog(没有 mvvm -> 没有用)

这很不错:使用 MVVM 模式时显示对话框(但它仍然使用自制的 ServiceLocator,我不需要它,因为我正在使用 IUnity 容器.我可以使用逻辑并将其重写为 Unity,但在我的诚实看来,这不是漂亮"的方式.>

在网上搜索信息一段时间后,一些博客(现在找不到来源)告诉我 PRISM 框架有一个叫做交互请求"的东西.所以我查看了prism文档并在高级mvvm场景"主题下找到了一小部分,但文档中提供的信息还不够.

我想知道是否有人有任何关于如何使用 mvvm 在prism wpf 中实现很棒的模态对话框的好例子或任何好的博文.

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

<块引用>

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

确实是个好问题.

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

解决方案

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

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>

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

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