Search code examples
windows-phone-7isolatedstorage

Where to access the isolated storage value?


  public IsolatedStorageSettings appSettings =
                  IsolatedStorageSettings.ApplicationSettings;


public Settings()
        {
            InitializeComponent();
             this.toggle.Checked += new EventHandler<RoutedEventArgs>(toggle_Checked);
             this.toggle.Unchecked += new EventHandler<RoutedEventArgs>(toggle_Unchecked);


 this.toggle.Click += new EventHandler<RoutedEventArgs>(toggle_Click);
            this.toggle.Indeterminate += new EventHandler<RoutedEventArgs>(toggle_Indeterminate);
    `}`

void toggle_Unchecked(object sender, RoutedEventArgs e) {

            this.toggle.Content = "Visibity is off";
            this.toggle.SwitchForeground = new SolidColorBrush(Colors.Red);
            appSettings.Add("value", "off");
        }

        void toggle_Checked(object sender, RoutedEventArgs e)
        {


            this.toggle.Content = "Visibity is on";
            this.toggle.SwitchForeground = new SolidColorBrush(Colors.Green);
            appSettings.Add("value", "on");
        }

        void toggle_Indeterminate(object sender, RoutedEventArgs e)
        {
            //add some content here
        }

        void toggle_Click(object sender, RoutedEventArgs e)
        {
            //add some content here


        }

by default calling checked method.If a user unchcked the button then again an user logged in app need to show the unchcked because the user previously unchcked the btn.but it's show checked.for that i am saving one value in isolated storage. can you please tell me where to access the isolated varieable value ?


Solution

  • You can access the isolatedstorage value in any page, in the same way as you created it.

    Try to access the value in Settings() constructor after the InitializeComponent();

    public Settings()
        {
            InitializeComponent();
            string value;
            if (appSettings.Contains("value"))
            {
                appSettings.TryGetValue("value", out value);
            }
    

    and then you can change the value of toggle button based on the 'value'.