Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO.IsolatedStorage;
- using System.Diagnostics;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Navigation;
- using Microsoft.Phone.Controls;
- using Microsoft.Phone.Shell;
- namespace flashlightSettings
- {
- public class AppSettings
- {
- IsolatedStorageSettings settings;
- const string CheckBoxSettingKeyName = "CheckBoxSetting";
- const bool CheckBoxSettingDefault = true;
- public AppSettings()
- {
- settings = IsolatedStorageSettings.ApplicationSettings;
- }
- public bool AddOrUpdateValue(string Key, Object value)
- {
- bool valueChanged = false;
- if (settings.Contains(Key))
- {
- if (settings[Key] != value)
- {
- settings[Key] = value;
- valueChanged = true;
- }
- }
- else
- {
- settings.Add(Key, value);
- valueChanged = true;
- }
- return valueChanged;
- }
- public T GetValueOrDefault<T>(string Key, T defaultValue)
- {
- T value;
- // If the key exists, retrieve the value.
- if (settings.Contains(Key))
- {
- value = (T)settings[Key];
- }
- // Otherwise, use the default value.
- else
- {
- value = defaultValue;
- }
- return value;
- }
- public void Save()
- {
- settings.Save();
- }
- public bool CheckBoxSetting
- {
- get
- {
- return GetValueOrDefault<bool>(CheckBoxSettingKeyName, CheckBoxSettingDefault);
- }
- set
- {
- if (AddOrUpdateValue(CheckBoxSettingKeyName, value))
- {
- Save();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement