C# 如何在cs页面之间传递变量?

C# 如何在cs页面之间传递变量?,c#,windows-phone-8,C#,Windows Phone 8,我在gotoWeb.xaml.cs中收集了用户输入,并将收集到的输入存储在独立的存储器中。我需要将存储的变量传递到MainPage.xmal.cs。我不知道怎么做 我需要MainPage.xaml中的var Page1和var Page2。如何做到这一点 在gotoWeb.xaml中编码 IsolatedStorageSettings.ApplicationSettings["Page1"] = site; IsolatedStorageSettings.ApplicationSettings.

我在
gotoWeb.xaml.cs
中收集了用户输入,并将收集到的输入存储在独立的存储器中。我需要将存储的变量传递到
MainPage.xmal.cs
。我不知道怎么做

我需要MainPage.xaml中的
var Page1
var 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"];

您可以在Messenger中查找MVVM模式。
您可以传递所有信息,而且实现起来非常简单。

当您使用应用程序设置时,即使退出应用程序,数据也会保持不变。如果这是您想要的,并且在应用程序重新启动后,如果您一进入MainPage就要加载此数据,则只需覆盖MainPage的On Navigated即可从应用程序设置加载数据

非常快而且脏:

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;

看看像MVVM Light这样的框架,它可能已经为您提供了这些基本功能。