Simple issue with isolated storage

I am trying to do a simple test with isolated storage, so I can use it for the Windows Phone 7 application that I am doing.

The test that I create sets a, creates the key and value with one button, and with the other button sets this value equal to the TextBlock text.

namespace IsoStore { public partial class MainPage : PhoneApplicationPage { // Constructor public MainPage() { InitializeComponent(); } public class AppSettings { IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings; private void button1_Click(object sender, RoutedEventArgs e) { appSettings.Add("email", " someone@somewhere.com "); } private void button2_Click(object sender, RoutedEventArgs e) { textBlock1.Text = (string)appSettings["email"]; } } } } 

This method gives me this error:

It is not possible to access the non-stationary member of the external type "IsoStore.MainPage" through the nested type "IsoStore.MainPage.AppSettings"

So, I tried this:

 namespace IsoStore { public partial class MainPage : PhoneApplicationPage { // Constructor public MainPage() { InitializeComponent(); } public class AppSettings { IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings; private void button1_Click(object sender, RoutedEventArgs e) { appSettings.Add("email", " someone@somewhere.com "); } } private void button2_Click(object sender, RoutedEventArgs e) { textBlock1.Text = (string)appSettings["email"]; } } } 

And instead, I get this error:

The name "appSettings" does not exist in the current context

So what obvious problem do I not see here?

Thanks so much for your time.

+6
c # visual-studio-2010 windows-phone-7 isolatedstorage
source share
2 answers

Application settings not available for button button2_Click

Refresh . Since IsolStorageSettings.ApplicationSettings is Static, there is no need for a link anyway. Just enter it.

 namespace IsoStore { public partial class MainPage : PhoneApplicationPage { // Constructor public MainPage() { InitializeComponent(); } private void button1_Click(object sender, RoutedEventArgs e) { IsolatedStorageSettings.ApplicationSettings.Add("email", " someone@somewhere.com "); } private void button2_Click(object sender, RoutedEventArgs e) { textBlock1.Text = (string)IsolatedStorageSettings.ApplicationSettings["email"]; } } } 
+4
source share

Try this code as there is no need to define the AppSettings class.

 namespace IsoStore { public partial class MainPage : PhoneApplicationPage { IsolatedStorageSettings appSettings; // Constructor public MainPage() { InitializeComponent(); appSettings = IsolatedStorageSettings.ApplicationSettings; } private void button1_Click(object sender, RoutedEventArgs e) { appSettings.Add("email", " someone@somewhere.com "); } private void button2_Click(object sender, RoutedEventArgs e) { textBlock1.Text = (string)appSettings["email"]; } } } 
0
source share

All Articles