导航到详细信息页面 - 共享视图模型或导航查询字符串?
从列表页面导航到详细信息页面时,有两种在页面之间传递选择数据的高级方法:共享视图模型实例和在导航 Uri 的查询字符串中传递标识符。
我应该使用哪个?使用一种方法相对于另一种方法是否存在任何问题(从视图模型访问当前 Uri、导航事件的计时等)?
When navigating from a list page to a details page, there are two high level ways of passing the selection data between the pages: sharing a view model instance and passing an identifier in the querystring of the navigation Uri.
Which should I be using? Are there any issues with using one approach over the other (access to current Uri from the view model, timing of navigation events, etc)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我个人建议将标识符作为导航 URI 查询字符串的一部分传递。当您的应用程序在逻辑删除后重新启用时,这些 URI 将恢复以形成后台堆栈。
当您的应用程序在逻辑删除后恢复时,您可以从应用程序状态重新创建应用程序视图模型,然后使用 URI 查询字符串将新创建的视图与其所需的 DataContext“结合”。
请参阅此处的工作示例:
http ://www.scottlogic.co.uk/blog/colin/2011/05/a-simple-windows-phone-7-mvvm-tombstoneing-example/
Personally I would recommend passing an identifier as part of the navigation URI querystring. These URIs are restored to form the back-stack when your application re-enabled after tombstoning.
When your application is restored after being tombstoned, you re-create your applications view model from the application state, then use the URI querystring to 'marry' your newly created view with its required DataContext.
See the worked example here:
http://www.scottlogic.co.uk/blog/colin/2011/05/a-simple-windows-phone-7-mvvm-tombstoning-example/
这两种方法都很好。
真正的区别在于逻辑删除过程。
当您返回到您的应用程序时,您的对象的 id 将
如果您选择共享视图模型,则在导航到时必须保存 id。
两者的混合似乎是最好的:您使用queryString导航,并使用sharedViewModel,因此当您导航到新页面时,您可以从queryString获取id,并使用该id从sharedViewModel获取数据!
您可以管理 SharedViewModel 将数据保存在isolatedStorage 中,以便在逻辑删除时恢复 Web 加载的数据
the two approches are quite well.
the real difference is in the tombstone process.
when you go back to your application, the id of your object will be parsed :
if you choose the shared viewmodel, you will have to save the id when you navigate to.
a mix of the two seems to be the best : you navigate with queryString, and use a sharedViewModel, so when you navigate to a new page, you got the id from queryString and get the data from the sharedViewModel with that id !
you can manage your SharedViewModel to save datas in the IsolatedStorage to recover web loaded datas when tombstonned