0
votes
  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 ?

2

2 Answers

1
votes

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'.

1
votes

It seems that you are not calling the Save method on the ApplicationSettings object.
Please read this guide on how you should work with isolated storage.

To save a setting:

IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
if (!settings.Contains("userData"))
{
settings.Add("userData", "some value");
}
else
{
settings["userData"] = "some value";
}
settings.Save();

To retrieve a setting:

if (IsolatedStorageSettings.ApplicationSettings.Contains("userData"))
{
 string result  IsolatedStorageSettings.ApplicationSettings["userData"] as string;
}

So in your case, save the state of the CheckBox in the Checked & UnChecked event, and load the state in the init of the page.