I’m working on a MVVM application, using MVVM Light and on the whole I’m finding it very nice to work with. I have a nagging issue however and hope someone can help.
I’m using sending instances of DialogMessage from VM to the View to display dialogs. The result is sent back to my VM via a callback, all good so far.
However the result of the dialog (OK, Yes, No, Cancel etc) is sent back as a member of the enum System.Windows.MessageBoxResult. This seems to go against the View/ViewModel separation to me, MessageBoxResult is clearly a type from the UI and so the VM shouldn’t be dependent upon this or anything from the System.Windows namespace.
What I’m looking for is someway of using DialogMessage with an alternative callback eg Action<UserResult>; rather than Action<System.Windows.MessageBoxResult>;, where UserResult is a type defined by me to represent the users choice without dependency on MessageBoxResult.
Is this possible or am I being too strict in me desire to keep UI concepts out of the VM?
In regards to the second part of your question, when I started working with MVVM Light I too felt that receiving a
MessageBoxResultback in the VM seems a little to UI-oriented.On the other hand, if only the name was different – such as UserResult as you suggested – would that be sufficient for you?
If only the nameing of the class is a problem, I think you can let it slip. The result
Ok, Yes, No, Canceldo not give an indication of whether a MessageBox was shown with buttons or whether it was some other kind of UI implementation (lets say a form with a combo box).If it still bothers you, you can always create a wrapper for the
DialogMessagewhich will raise the Dialog, get theMessageBoxResultand return aUserResultwhich can be an enum with the same values (think of it as a simple converter).But as I said, I think it might be an overkill…