locked
Save checkboxes when app shuts down RRS feed

  • Question

  • Hi i need a way so save a checkboxes array when the app shutdown so i could display it when the app opens again.
    Saturday, April 19, 2014 6:58 PM

Answers

  • It's easier to save the value of the checkboxes rather than the checkboxes themselves.

    Try this:

    Assume there are 3 CheckBoxes

    Save their value on App suspending event:

            async void App_Suspending(Object sender, Windows.ApplicationModel.SuspendingEventArgs e)
            {
                // TODO: This is the time to save app data in case the process is terminated
                var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
    
                Boolean[] ArrChkValues = new Boolean[] { Chk1.IsChecked.Value, Chk2.IsChecked.Value, Chk3.IsChecked.Value };
    
                localSettings.Values["CheckBoxeValues"] = ArrChkValues;
            }
     

    Retrieve the value when the App loads and set the value of the Check Boxes accordingly:

    protected override void OnNavigatedTo(NavigationEventArgs e) { Application.Current.Suspending += new SuspendingEventHandler(App_Suspending); var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; Object value = localSettings.Values["CheckBoxeValues"]; if (value == null) { // No data } else { Boolean[] ArrChkValues = (Boolean[])value; if (ArrChkValues[2] ==true) { Chk3.IsChecked = true; }

    //Check for other Check Boxes } }


    Saturday, April 19, 2014 9:40 PM

All replies

  • Hi,

    You can use the suspending event handler to save everything  before the App shuts down.

    Easiest way is to save in LocalSettings and read everything from it when the app starts or resumes.

    http://msdn.microsoft.com/en-US/library/windows/apps/xaml/hh465115.aspx

    Saturday, April 19, 2014 7:36 PM
  • I know how to triger the event and when but i dont know how am i suppoused to save the array of checkboxes...
    Saturday, April 19, 2014 8:02 PM
  • It's easier to save the value of the checkboxes rather than the checkboxes themselves.

    Try this:

    Assume there are 3 CheckBoxes

    Save their value on App suspending event:

            async void App_Suspending(Object sender, Windows.ApplicationModel.SuspendingEventArgs e)
            {
                // TODO: This is the time to save app data in case the process is terminated
                var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
    
                Boolean[] ArrChkValues = new Boolean[] { Chk1.IsChecked.Value, Chk2.IsChecked.Value, Chk3.IsChecked.Value };
    
                localSettings.Values["CheckBoxeValues"] = ArrChkValues;
            }
     

    Retrieve the value when the App loads and set the value of the Check Boxes accordingly:

    protected override void OnNavigatedTo(NavigationEventArgs e) { Application.Current.Suspending += new SuspendingEventHandler(App_Suspending); var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; Object value = localSettings.Values["CheckBoxeValues"]; if (value == null) { // No data } else { Boolean[] ArrChkValues = (Boolean[])value; if (ArrChkValues[2] ==true) { Chk3.IsChecked = true; }

    //Check for other Check Boxes } }


    Saturday, April 19, 2014 9:40 PM