2

The project I am working on is a desktop based WPF application. I have implemented the MVVM pattern in it. Also I am using Unity IoC and the Repository Pattern in it.

I have a problem in a master details type scenario. I navigate to the details Page(I have used IoC to expose the NavigationService in the ViewModel) but I dont know how can I get the employeeID in the EmployeeDetails ViewModel without breaking the MVVM pattern. I don't want to write anything in code behind.

Any pointers will be very helpful.

Regards.

Shoaib Shaikh
  • 4,565
  • 1
  • 27
  • 35

1 Answers1

0

Normally, you achieve this by exposing a property CurrentEmployee in your EmployeeMasterViewModel. This property is data bound to the currently selected item in the master list.
You then bind the controls of the details page to the properties of CurrentEmployee.

Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443
  • This could be possible if both master and details viewmodel are nested somehow in a class.. but what i am talking about is two different/seperate Views having different ViewModels, i am navigating from one view to another using NavigationService. – Shoaib Shaikh Sep 07 '11 at 06:44
  • Can't you use [this overload of Navigate](http://msdn.microsoft.com/en-us/library/ms591042.aspx) to pass in the currently selected employee? – Daniel Hilgarth Sep 07 '11 at 06:54
  • no because i can't refer to View's Class from my ViewModel, just to preserve separation of concerns and MVVM pattern. i can only navigate to page using a uri. – Shoaib Shaikh Sep 07 '11 at 09:11
  • There is another overload that accepts an Uri as first parameter and an arbitrary object as second parameter... – Daniel Hilgarth Sep 07 '11 at 09:21
  • yup i have also tried that.. but unfortunately i am unable to get e.ExtraData at my details page. http://social.msdn.microsoft.com/forums/en-US/wpf/thread/a54e19b8-ee1d-4e2c-81cb-760e2c3264df/ this explains that problem.. and seems no mvvm oriented solution there – Shoaib Shaikh Sep 07 '11 at 09:23