简体   繁体   English

WP7 NavigationService.Navigate传递指针而不使用全局变量?

[英]WP7 NavigationService.Navigate pass a pointer without using global variables?

I am navigating to page X in WP7. 我导航到WP7中的第X页。 I have an object (let's call it banana) in my ViewModel, which is where the NavigationService.Navigate call is being made. 我的ViewModel中有一个对象(我们称其为香蕉),在该对象中进行NavigationService.Navigate调用。 Page X needs a reference to the banana. X页面需要引用香蕉。 How can I do that? 我怎样才能做到这一点?

The answer to this question recommends using the global App class. 在回答这个问题,建议使用全球App类。 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. 对我来说不是一个好选择,因为我可能有X页面类的多个实例,并且如果以后再导航到其他实例,我也不会感到困惑。

I would also prefer not to have to serialize the banana. 我也希望不必序列化香蕉。

如果页面可能有多个实例,则需要将其需要的所有参数作为用于导航的Uri中的querystring的一部分传递。

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. 您可以按照@Matt的建议使用查询字符串(例如,发送ID),也可以通过消息发送对象本身,例如,可以使用MVVM Light的Messenger类。

Hope this helps :) 希望这可以帮助 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM