Windows Phone 8.1 – Read/Save Settings Isolated Storage
May 30, 2014 Leave a comment
This article walks you through the steps for creating and read settings in your Windows Phone application. On this demo, we will use IsolatedStorage to store and retrieve data on the application.
STEP 1 – Create Windows Phone Application
- Open Visual Studio 2013 and create a new project of type Windows Phone App.
- On this project I create a solution called WindowsPhoneIsolatedStorage.
- After project creation, we need to implement the design. On this example, we need two textboxes and two buttons. A textbox to enter de setting and another one to enter the value of that setting. The buttons, will be used to save and read the settings information.
STEP 2 – Save/Read Settings Implementation
private void Save_Click(object sender, RoutedEventArgs e) { IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings; if (!settings.Contains(txtSettings.Text)) { settings.Add(txtSettings.Text, txtValue.Text); } else { settings[txtSettings.Text] = txtValue.Text; } settings.Save(); }
private void Read_Click(object sender, RoutedEventArgs e) { if (IsolatedStorageSettings.ApplicationSettings.Contains(txtSettings.Text)) { txtValue.Text = IsolatedStorageSettings.ApplicationSettings[txtSettings.Text].ToString(); } }
STEP 3 – Run Application
Press F5 and check the result of the implementation. If you save a setting called “database” with value demo, and then remove the value and try to read the setting, the demo value will be displayed on the screen.