Как вы успешно реализовали функциональность MessageBox.Show () в MVVM?

У меня есть приложение WPFwhich calls MessageBox.Show() way back in the ViewModel (чтобы проверить, действительно ли пользователь хочет удалить).This actually works, ноgoes against the grain of MVVM поскольку ViewModel не должен явно определять, что происходит с View.

Так что теперь я думаюhow can I best implement the MessageBox.Show() functionality в моем приложении MVVM, варианты:

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 для того, что раньше было несколько строк кода с MessageBox.Show ().

In what ways have you successfully implemented Dialogue Boxes in your MVVM applications?

Ответы на вопрос(12)

Ваш ответ на вопрос