0

I have always read that is not a good solution to use in the view model the messageBox to show a dialog when it is used the MVVM pattern.

Show I think that the other solution is create a view and a view model that is create in my main view model and related the view and the view model of the dialog. Additionally, I need to create a class that is passed from the main view model to the dialog view model that is returned as result of the dialog.

But really the second way is better? what is it the difference? because in both cases I need to wait until the result of the dialog.

Or both of t he solutions are a bad option?

Thanks.

4

1 回答 1

2

In my opinion, creating a ViewModel for a MessageBox is overkill. I'd create an interface for ViewModels with a ShowMessage event, and an attached behavior with an attached property that can bind to the ViewModel, register a listener for the ShowMessage event, and opens a MessageBox when the event is raised. The result of the message box could be passed through the EventArgs.

The difference here would be that you can encapsulate the interface and the attached behaviour in a reusable component, and that you need minimal code in the ViewModel to use it.

于 2013-05-05T10:36:25.230 回答