2013-08-30 43 views
0

我收集了gotoWeb.xaml.cs中的用户输入,并将收集的输入存储在隔离存储中。我需要将存储的变量传递给MainPage.xmal.cs。我不知道该怎么做?如何在cs页面之间传递变量?

我在MainPage.xaml中需要此var Page1var Page2。这个怎么做 ?

守则gotoWeb.xaml

IsolatedStorageSettings.ApplicationSettings["Page1"] = site; 
IsolatedStorageSettings.ApplicationSettings.Save(); 
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings; 
//store it in the settings 
if (!settings.Contains("qsPage1")) 
{ 
//if setting has not been created, add it 
settings.Add("qsPage1", site); 
} 
else 
{ 
//store a the page in the setting 
settings["qsPage1"] = site; 
} 
var Page1 = IsolatedStorageSettings.ApplicationSettings["qsPage1"]; 
// and by using same isolated settings method, created one more varible 
var Page2 = IsolatedStorageSettings.ApplicationSettings["qsPage2"]; 
+0

看看像MVVM光框架可能已经为你提供这些基本功能。 –

回答

0

当您使用ApplicationSettings时,即使退出应用程序,数据也会保留。如果这是你想要的,并且如果这个数据在应用程序重新启动后一旦进入MainPage也要被加载,那么只需重写MainPage的OnNavigatedTo以从ApplicationSettings加载数据。

0

你可以看看信使MVVM模式。 你可以通过一切,它很容易实现。

-1

非常快速和肮脏的:

page1.xml: 
public class values 
    { 
     public static var value1 = 123; 
     public static var value2 = 234; 
     public static var value3 = 345; 


    } 

page2.xml: 

var localvalue1 = page1.values.value1; 
var localvalue2 = page1.values.value2; 
var localvalue3 = page1.values.value3;