Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 独立存储设置(从不同视图保存和检索)_C#_Xaml_Windows Phone 7_Isolatedstorage - Fatal编程技术网

C# 独立存储设置(从不同视图保存和检索)

C# 独立存储设置(从不同视图保存和检索),c#,xaml,windows-phone-7,isolatedstorage,C#,Xaml,Windows Phone 7,Isolatedstorage,我有两个视图(MainPage.xaml和Settings.xaml) 我想在我的设置视图中保存一个字符串 &在主页中检索其内容 这是我的代码,但我得到一个错误: Settings.xaml.cs: var settings = IsolatedStorageSettings.ApplicationSettings; settings.Add("setPlan", "This is my text that i want to retreive"); var l

我有两个视图(MainPage.xaml和Settings.xaml)

我想在我的设置视图中保存一个字符串 &在主页中检索其内容

这是我的代码,但我得到一个错误:

Settings.xaml.cs:

var settings = IsolatedStorageSettings.ApplicationSettings;
                settings.Add("setPlan", "This is my text that i want to retreive");
var location = settings["setPlan"].ToString();
MainPage.xaml.cs:

var settings = IsolatedStorageSettings.ApplicationSettings;
                settings.Add("setPlan", "This is my text that i want to retreive");
var location = settings["setPlan"].ToString();
错误是:名称“设置”在当前上下文中不存在

但是这个“setPlan”字符串不应该在我的沙箱中,并且可以从任何视图访问吗?

您不需要:

var settings = IsolatedStorageSettings.ApplicationSettings; 
var location = settings["setPlan"].ToString(); 
MainPage.xaml.cs

settings
看起来它的作用域是settings.xaml.cs中调用它的方法