WP7 NavigationService.Navigate 传递指针而不使用全局变量?
我正在 WP7 中导航到第 X 页。我的 ViewModel 中有一个对象(我们称之为香蕉),这是进行 NavigationService.Navigate 调用的地方。第 X 页需要引用香蕉。我怎样才能做到这一点?
此问题的答案建议使用全局 App 类。对我来说这不是一个好的选择,因为我可能有页面 X 的类的多个实例,并且如果以后导航到其他实例,我不想混淆它们。
我也不想序列化香蕉。
I am navigating to page X in WP7. I have an object (let's call it banana) in my ViewModel, which is where the NavigationService.Navigate call is being made. Page X needs a reference to the banana. How can I do that?
The answer to this question recommends using the global App class. Not a good option for me because I might have multiple instances of the class of page X, and I wouldn't want to confuse other instances if they are later navigated to.
I would also prefer not to have to serialize the banana.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果页面可能有多个实例,那么您需要将其所需的任何参数作为用于导航的 Uri 中的查询字符串的一部分传递。
If there could be multiple instances of the page then you'll need to pass any parameters it needs as part of the querystring in the Uri you use for navigation.
您可以按照@Matt的建议使用查询字符串(例如发送ID),也可以通过消息发送对象本身,例如,您可以使用来自的
Messenger
类MVVM Light 就是为此而生。希望这有帮助:)
You can either use the query string (to send the id, for example) as suggested by @Matt, and you could also send the object itself via a message for example, you can use the
Messenger
class from MVVM Light for that.Hope this helps :)