如何在 Silverlight 4 中的页面之间传递复杂对象棱镜
我在我的应用程序中使用 Silverlight 4 + PRISM + MVVM。我想将一个复杂的对象传递到另一个页面。我不知道该怎么做。我不能/不想使用 URI 参数。
I am using Silverlight 4 + PRISM + MVVM in my application. I want to pass a complex object to another page. I dont know how to do that. I cant/dont want to use URI parameters.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许 EventAggreagtor 会很有用
Maybe EventAggreagtor will be usefull
“有求必应”是 Unity 的方式。您可以与任何其他统一对象共享注册为单例的对象。只需在视图模型的构造函数中指定该共享对象的接口即可。
正如 Dmitry Kushnier 所提到的,您还可以通过 EventAggregator 将复杂类型作为参数传递。
"Ask for what you want" is the Unity way. You can share objects registered as singletons with any other unity objects. Just specify the interface of that shared object in the constructor of your viewmodels.
As mentioned by Dmitry Kushnier you can also pass complex types as parameters via the EventAggregator.
我实现了 INavigationAware 接口,并在 OnNavigateFrom() 方法中的 navigationContext.NavigationService.Region.Context 中设置了复杂对象。现在在下一页中,我再次实现了 INavigationAware 接口,现在我在 OnNavigateTo() 中检查相同的值以获取该值。
更新:我在另一个问题中发布了带有代码的答案。这里提一下供参考 -
首先从 INavigationAware 接口派生视图模型 -
然后你可以实现 OnNavigateFrom 并设置你想要传递的对象作为导航上下文,如下 -
当你想要接收数据时,在第二个视图模型 -
希望对大家有帮助!
I implemented INavigationAware interface, and set the complex object in navigationContext.NavigationService.Region.Context in OnNavigatedFrom() method. Now in the next page, again I implemented INavigationAware interface and now I check for the same value in OnNavigatedTo() to get the value.
Update: I posted answer with code in another question. Mentioning it here for reference -
First derive the viewmodel from INavigationAware interface -
You can then implement OnNavigatedFrom and set the object you want to pass as navigation context as follows -
and when you want to receive the data, add the following piece of code in the second view model -
hope it helps you all!