0

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.

mans
  • 17,104
  • 45
  • 172
  • 321
  • if your ViewModel is in the same assembly as the view, which means it's got a reference to `System.Windows`, simply `MessageBox.Show()`. Keep it simple, unless you're doing multi-platform type of stuff and need to keep it all separate and independent from WPF specific matters. – Federico Berasategui Mar 17 '14 at 18:39
  • Does this answer your question? [How have you successfully implemented MessageBox.Show() functionality in MVVM?](https://stackoverflow.com/questions/1098023/how-have-you-successfully-implemented-messagebox-show-functionality-in-mvvm) – StayOnTarget Apr 22 '20 at 20:58

1 Answers1

0

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.

eFloh
  • 2,098
  • 20
  • 24