如何在 PRISM 4 中导航到新视图时传递对象
我正在开发一个 PRISM 应用程序,我们可以深入研究数据(以获取更多详细信息)。 在我的实现中,我有一个嵌套的 MVVM,当我沿着树导航时,我想将模型传递给我新创建的视图。
据我所知,目前 PRISM 允许传递字符串,但不允许传递对象。我想知道有哪些方法可以解决这个问题。
I am working on a PRISM application where we drill down into the data (to get more details).
In my implementation I have a nested MVVM and when I navigate down the tree I would like to pass a model to a my newly created view.
As far as I know, currently PRISM allows to pass strings, but doesn't allow to pass objects. I would like to know what are the ways of overcoming this issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我通常使用一个服务来注册我想要通过 guid 传递的对象。这些存储在哈希表中,当在 prism 中导航时,我将 guid 作为参数传递,然后可以使用该参数来检索对象。
希望这对你有意义!
i usually use a service where i register the objects i want to be passed with a guid. these get stored in a hashtable and when navigating in prism i pass the guid as a parameter which can then be used to retrieve the object.
hope this makes sense to you!
我将使用 OnNavigedTo 和 OnNavieratedFrom 方法通过 NavigationContext 传递对象。
首先从 INavigationAware 接口派生视图模型 -
然后您可以实现 OnNavieratedFrom 并将要传递的对象设置为导航上下文,如下所示 -
当您想要接收数据时,在第二个视图模型中添加以下代码 -
ps。如果有帮助,请将此标记为答案。
I would use the OnNavigatedTo and OnNavigatedFrom methods to pass on the objects using the NavigationContext.
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 -
ps. mark this as answer if this helps.
PRISM 支持提供参数:
并在您的 View、ViewModel 或两者上实现 INavigationAware 接口。
您还可以在此处找到详细信息:https:// msdn.microsoft.com/en-us/library/gg430861%28v=pandp.40%29.aspx
PRISM supports supplying parameters:
and implement the INavigationAware interface on your View, ViewModel or both.
you can also find details here: https://msdn.microsoft.com/en-us/library/gg430861%28v=pandp.40%29.aspx