Add view to region and pass data

Oct 16, 2009 at 4:18 AM

I have a structure in 1 module

   - EmployeeListView (binding list of employee model)
   - EmployeeListPresentationModel

   - EmployeeCompositionView
   - EmployeeCompositionPresentationModel

 - Double click on selected employee in EmployeeListView => Show EmployeeCompositionView and pass selected employee to EmployeeCompositionPresentationModel

What should i do:

  1. EmployeeCompositionPresentationModel employeeCompositionPresentationModel = container.Resolve<EmployeeCompositionPresentationModel>();
    employeeCompositionPresentationModel.SelectedEmployee = SelectedEmployee;
    RegionManager.RegisterViewWithRegion(RegionNames.MainRegion, employeeCompositionPresentationModel.View);
  2. Using controller (how do i do?).
  3. Using EventAggregator.
  4. Or ....

Thanks for help.

Oct 16, 2009 at 2:09 PM


For this particular situation, a possible approach could be using a Controller or any other component that is in charge of orchestrating the views for an entire module. Ward Bell talks a bit more about a component like this in these posts (Screen Factory and Birth and Death of M-V-VM Triads). You can notify the “coordinator” from your EmployeeListPresentationModel about the employee changing (passing the employee as parameter) and then creating the view as you are doing in 1).

Please let me know if this helps.

Damian Schenkelman

Oct 17, 2009 at 8:00 AM

Hi Damian, thank for quick reply. It usefull for me.

And another question: How i can implement global shortkeys (e.g: Ctrl + N) for show edit view or something like that.

EmployeeListView(is active in ContentControl) => press Ctrl + N => Show EmployeeCompositionView to add new Employee.
CustomerListView(active in ContentControl) => press Ctrl + N => Show CustomerCompositionView to add new Customer.
And so on.

Thank for your helps.



Oct 20, 2009 at 6:10 PM


This kind of functionality is not addressed by the guidance but there are different ways to do it. Lester Lobo recently blogged about CoreMVVM: A basic MVVM framework, which uses the MVVM toolkit to, among other things, provide support for DelegateCommands and KeyBindings.

You can download the library from here.

Please let me know if this helps.

Damian Schenkelman