2

Depending upon certain conditions a WPF app I'm working on has to be able to bring up a dialog box, to remind the user to save their data. We're using ModernUI for our basic look-and-feel. We're also using MVVM Light. The problem I'm struggling with is how to invoke a ModernUI's ModernDialog from within one of the commands in a viewmodel. We have a class (DialogViewService) to make it a bit easier in using the ModernDialog, and do I initially tried this:

var dial = new CoreServices.DialogViewService();
var ret = dial.ShowMessage("Unsaved Data", "Save Current Data?");

I don't like that, though because it's in my VM. So I then put a property into our ServiceLocator and changed the above code to this:

var dial = ViewModelLocator.DialogViewSrv;
var ret = dial.ShowMessage("Unsaved Data", "Save Current Data?");

Really though, this is the same thing as the previous one.

So how do I get it so that I can invoke the ModernDialog from a VM, without giving the VM "knowledge" of the UI?

Rod
  • 4,107
  • 12
  • 57
  • 81
  • I don't see what's wrong here, this is one of the ways to use a dialog service. You can rename `ShowMessage` to `NotifyUser` or something, just to make it feel less UI-related. – mechanic Apr 12 '17 at 22:24
  • 1
    wrap the service behind an abstraction and inject it into the view model. Try to avoid coupling your VM to UI concerns and concretions. – Nkosi Apr 13 '17 at 01:57

0 Answers0