How can I pass objects to ViewModels using Navigat

2019-07-19 12:02发布

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.

1条回答
时光不老,我们不散
2楼-- · 2019-07-19 12:35

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.

查看更多
登录 后发表回答