简体   繁体   English

在Windows Phone中跨页面使用值的最佳方法?

[英]Best way to use the values across the pages in Windows phone?

Basically i get some of the values in the Page 1 then i need to use it in the Page 3 and Page 5. 基本上我在第1页中获得了一些值,然后需要在第3页和第5页中使用它。

So i store this values by using the following code. 所以我通过使用以下代码存储此值。

if (!PhoneApplicationService.Current.State.ContainsKey(key))
   PhoneApplicationService.Current.State.Add(key, value);
else
   PhoneApplicationService.Current.State[key] = value;

Then i will retrieve it in the Page 3 and Page 5. 然后,我将在第3页和第5页中检索它。

I will use more than 50 - 100 objects to use the above code. 我将使用超过50-100个对象来使用上述代码。 So will it lead to memory leak ?... 那会导致内存泄漏吗?...

Or Anyone suggest me to use the variables across the pages [ Page 1 to Page 3 ] without using the above approach ? 还是有人建议我在不使用上述方法的情况下在页面[第1页至第3页]中使用变量?

Perhaps you should try implementing the MVVM pattern and binding all of your pages to a single ViewModel, therefore each page will have access to the same 'state' 也许您应该尝试实现MVVM模式并将所有页面绑定到一个ViewModel,因此每个页面都可以访问相同的“状态”

http://msdn.microsoft.com/en-us/library/gg521153(v=vs.92).aspx http://msdn.microsoft.com/zh-CN/library/gg521153(v=vs.92).aspx

is the amount of variable fix? 固定金额是多少? if it is, perhaps you can create global variable in App.cs and save the value to those global variables and retrieve them after you navigate to those page. 如果是这样,也许您可​​以在App.cs中创建全局变量,然后将值保存到这些全局变量中,并在导航到这些页面后检索它们。

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

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