Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple Isolated Storage Problem

I am trying to do a simple test with Isolated Storage so I can use it for a Windows Phone 7 application I am making.

The test I am creating sets a creates a key and value with one button, and with the other button sets that value equal to a TextBlock's 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", "[email protected]");
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            textBlock1.Text = (string)appSettings["email"];
        }
    }      
}
}

This way gives me this error:

Cannot access a non-static member of outer type 'IsoStore.MainPage' via 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", "[email protected]");
        }

    }

    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 am I overlooking here?

Thanks so much for your time.

like image 746
Dan Avatar asked Dec 29 '10 00:12

Dan


People also ask

For what purpose is used the isolated storage?

Using isolated storage enables partially trusted applications to store data in a manner that is controlled by the computer's security policy. This is especially useful for downloaded components that a user might want to run cautiously.

What is isolated storage file?

Isolated storage is designed to prevent data corruption and access to application-specific data, while providing a standard data storage and retrieval system that's inaccessible to users, folders or applications. Isolated storage serves as a virtual file system managed by the . NET Common Language Runtime (CLR).


1 Answers

appSettings is out of scope for button2_Click

Update Since IsolatedStorageSettings.ApplicationSettings is Static anyway there's no need for the reference at all. Just directly access it.

namespace IsoStore
{

 public partial class MainPage : PhoneApplicationPage
 {


    // Constructor
    public MainPage()
    {
    InitializeComponent();


    }


    private void button1_Click(object sender, RoutedEventArgs e)
    {
    IsolatedStorageSettings.ApplicationSettings.Add("email", "[email protected]");
    }



    private void button2_Click(object sender, RoutedEventArgs e)
    {
       textBlock1.Text = (string)IsolatedStorageSettings.ApplicationSettings["email"];
    }
  }
}
like image 113
Conrad Frix Avatar answered Oct 18 '22 16:10

Conrad Frix