如何使用 NavigationService 将对象传递给 ViewModel?
我正在从事的项目是一个基于桌面的 WPF 应用程序。我在其中实现了MVVM模式。我还使用 Unity IoC 和其中的存储库模式。
我在主详细信息类型场景中遇到问题。我导航到详细信息页面(我已使用 IoC 在 ViewModel 中公开 NavigationService),但我不知道如何在不破坏 MVVM 模式的情况下获取 EmployeeDetails ViewModel 中的员工 ID。我不想在后面的代码中写任何东西。
任何指示都会非常有帮助。
问候。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常,您可以通过在
EmployeeMasterViewModel
中公开属性CurrentEmployee
来实现此目的。此属性是绑定到主列表中当前选定项目的数据。然后,您将详细信息页面的控件绑定到
CurrentEmployee
的属性。Normally, you achieve this by exposing a property
CurrentEmployee
in yourEmployeeMasterViewModel
. 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
.