How have you successfully implemented MessageBox.Show() functionality in MVVM?
Posted
by Edward Tanguay
on Stack Overflow
See other posts from Stack Overflow
or by Edward Tanguay
Published on 2009-07-08T13:19:12Z
Indexed on
2010/03/11
21:29 UTC
Read the original article
Hit count: 471
I've got a WPF application which calls MessageBox.Show() way back in the ViewModel (to check if the user really wants to delete). This actually works, but goes against the grain of MVVM since the ViewModel should not explicitly determine what happens on the View.
So now I am thinking how can I best implement the MessageBox.Show() functionality in my MVVM application, options:
I could have a message with the text "Are you sure...?" along with two buttons Yes and No all in a Border in my XAML, and create a trigger on the template so that it is collapsed/visible based on a ViewModelProperty called AreYourSureDialogueBoxIsVisible, and then when I need this dialogue box, assign AreYourSureDialogueBoxIsVisible to "true", and also handle the two buttons via DelegateCommand back in my ViewModel.
I could also somehow try to handle this with triggers in XAML so that the Delete button actually just makes some Border element appear with the message and buttons in it, and the Yes button did the actually deleting.
Both solutions seem to be too complex for what used to be a couple lines of code with MessageBox.Show().
In what ways have you successfully implemented Dialogue Boxes in your MVVM applications?
© Stack Overflow or respective owner