简体   繁体   English

如何在wpf mvvm应用程序中显示消息框?

[英]how to show a message box in a wpf mvvm application?

I have an application whch is written in WPF and is based on MVVM. 我有一个应用程序是用WPF编写的,并且基于MVVM。

In part of this application, I am doing a very long processing and at the end of it I want to ask a question from user such as processing finished, do you want to reset data? 在此应用程序的一部分中,我正在做一个很长的处理,最后,我想向用户提出一个问题,例如处理完成,是否要重置数据?

I am doing this by showing a message box and it do the job, but I belive it is not a good solution as my ViewModel showing something to user . 我通过显示一个消息框来做到这一点,它可以完成工作,但是我相信这不是一个很好的解决方案,因为ViewModel向用户显示了一些东西。

What is the best way to implement such messagebox? 实现这种消息框的最佳方法是什么?

I read the answer to similar questions here but all of them related to input validation, whish is not the case here. 我在这里阅读了类似问题的答案,但所有这些问题都与输入验证有关,而事实并非如此。 In my case, I am asking a question which is not related to data validation and hence data vlidation methods doesn't work here. 就我而言,我问的一个问题与数据验证无关,因此数据滑动方法在这里不起作用。

An elegant way would be using a "MessageRequest" that is raised in the ViewModel and handled in the View (--> Interactions) or an Interaction Service defined in the View Layer. 一种优雅的方法是使用在ViewModel中引发并在View(-> Interactions)或在View Layer中定义的Interaction Service处理的“ MessageRequest”。 Thus, the ViewModel wouldn't decide HOW the message is shown, as this is part of the UI. 因此,ViewModel不会决定如何显示消息,因为这是UI的一部分。 See http://msdn.microsoft.com/en-us/library/gg405494(v=pandp.40).aspx#sec11 and following section for a good example. 请参见http://msdn.microsoft.com/zh-cn/library/gg405494(v=pandp.40).aspx#sec11和以下部分,以获取一个很好的示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM