1

I have a window with a list, where clicking a list entry will show a new window for a detail view of that item

What is the cleanest way to do this in MVVM? I thought of just doing a container.Resolve<IViewType>().Show() and have Unity create all the dependencies, but just calling Show() sounds un-MVVM. Should I create some sort of WindowService manager class or would this be overkill? What layer of code is it acceptable for code to call Show()?

Secondly, how would I pass parameters (eg CustomerID and ProductID) from the initiating view-model to the new view-model that will be attached to the new window being shown?

Hakan Fıstık
  • 16,800
  • 14
  • 110
  • 131
blue18hutthutt
  • 3,191
  • 5
  • 34
  • 57

2 Answers2

0

I generally prefer to create a NavigationService that handles instantiating windows and view models and sets the view model as the data context. Then you can call this from within your parent viewmodel and they are decoupled.

Michael Christensen
  • 1,768
  • 1
  • 13
  • 11
  • I had similar thoughts - that seems to be most consistent with the spirit of MVVM. But how would I pass the parameters from one view-model to the other? – blue18hutthutt Nov 04 '12 at 06:54
  • Its an interesting dilema. It depends on how cohesive you think the two views need to be. The most straight forward would be to just pass the IDs into the navigation methods. – Michael Christensen Nov 04 '12 at 06:57
  • Remember a lot of times the best pattern only emerges after the fact. – Michael Christensen Nov 04 '12 at 07:02
  • I could see the value of a NavigationService and it would certainly kill two birds with one stone here. Could possibly even use the Prism NavigationService directly, since this already has a convenient URI-based view-navigation system – blue18hutthutt Nov 04 '12 at 07:04
-1

I use this approach for dialogs with MVVM.

All I have to do now is call the following from my view model.

var result = this.uiDialogService.ShowDialog("Dialogwindow title goes here", dialogwindowVM);
Community
  • 1
  • 1
blindmeis
  • 22,175
  • 7
  • 55
  • 74