如何使用 NavigationService 将对象传递给 ViewModel?

发布于 2024-12-03 02:10:21 字数 262 浏览 0 评论 0原文

我正在从事的项目是一个基于桌面的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一页 2024-12-10 02:10:21

通常,您可以通过在 EmployeeMasterViewModel 中公开属性 CurrentEmployee 来实现此目的。此属性是绑定到主列表中当前选定项目的数据。
然后,您将详细信息页面的控件绑定到 CurrentEmployee 的属性。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文