简体   繁体   中英

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.

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 .

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. Thus, the ViewModel wouldn't decide HOW the message is shown, as this is part of the UI. See http://msdn.microsoft.com/en-us/library/gg405494(v=pandp.40).aspx#sec11 and following section for a good example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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