博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Create a Settings Page for Windows phone
阅读量:6449 次
发布时间:2019-06-23

本文共 5744 字,大约阅读时间需要 19 分钟。

using System;using System.IO.IsolatedStorage;using System.Diagnostics;using System.Collections.Generic;namespace SettingsSample{    public class AppSettings    {        // Our isolated storage settings        IsolatedStorageSettings settings;        // The isolated storage key names of our settings        const string CheckBoxSettingKeyName = "CheckBoxSetting";        const string ListBoxSettingKeyName = "ListBoxSetting";        const string RadioButton1SettingKeyName = "RadioButton1Setting";        const string RadioButton2SettingKeyName = "RadioButton2Setting";        const string RadioButton3SettingKeyName = "RadioButton3Setting";        const string UsernameSettingKeyName = "UsernameSetting";        const string PasswordSettingKeyName = "PasswordSetting";        // The default value of our settings        const bool CheckBoxSettingDefault = true;        const int ListBoxSettingDefault = 0;        const bool RadioButton1SettingDefault = true;        const bool RadioButton2SettingDefault = false;        const bool RadioButton3SettingDefault = false;        const string UsernameSettingDefault = "";        const string PasswordSettingDefault = "";        ///         /// Constructor that gets the application settings.        ///         public AppSettings()        {            // Get the settings for this application.            settings = IsolatedStorageSettings.ApplicationSettings;        }        ///         /// Update a setting value for our application. If the setting does not        /// exist, then add the setting.        ///         ///         ///         /// 
public bool AddOrUpdateValue(string Key, Object value) { bool valueChanged = false; // If the key exists if (settings.Contains(Key)) { // If the value has changed if (settings[Key] != value) { // Store the new value settings[Key] = value; valueChanged = true; } } // Otherwise create the key. else { settings.Add(Key, value); valueChanged = true; } return valueChanged; } /// /// Get the current value of the setting, or if it is not found, set the /// setting to the default setting. /// ///
/// /// ///
public T GetValueOrDefault
(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; } ///
/// Save the settings. /// public void Save() { settings.Save(); } ///
/// Property to get and set a CheckBox Setting Key. /// public bool CheckBoxSetting { get { return GetValueOrDefault
(CheckBoxSettingKeyName, CheckBoxSettingDefault); } set { if (AddOrUpdateValue(CheckBoxSettingKeyName, value)) { Save(); } } } ///
/// Property to get and set a ListBox Setting Key. /// public int ListBoxSetting { get { return GetValueOrDefault
(ListBoxSettingKeyName, ListBoxSettingDefault); } set { if (AddOrUpdateValue(ListBoxSettingKeyName, value)) { Save(); } } } ///
/// Property to get and set a RadioButton Setting Key. /// public bool RadioButton1Setting { get { return GetValueOrDefault
(RadioButton1SettingKeyName, RadioButton1SettingDefault); } set { if (AddOrUpdateValue(RadioButton1SettingKeyName, value)) { Save(); } } } ///
/// Property to get and set a RadioButton Setting Key. /// public bool RadioButton2Setting { get { return GetValueOrDefault
(RadioButton2SettingKeyName, RadioButton2SettingDefault); } set { if (AddOrUpdateValue(RadioButton2SettingKeyName, value)) { Save(); } } } ///
/// Property to get and set a RadioButton Setting Key. /// public bool RadioButton3Setting { get { return GetValueOrDefault
(RadioButton3SettingKeyName, RadioButton3SettingDefault); } set { if (AddOrUpdateValue(RadioButton3SettingKeyName, value)) { Save(); } } } ///
/// Property to get and set a Username Setting Key. /// public string UsernameSetting { get { return GetValueOrDefault
(UsernameSettingKeyName, UsernameSettingDefault); } set { if (AddOrUpdateValue(UsernameSettingKeyName, value)) { Save(); } } } ///
/// Property to get and set a Password Setting Key. /// public string PasswordSetting { get { return GetValueOrDefault
(PasswordSettingKeyName, PasswordSettingDefault); } set { if (AddOrUpdateValue(PasswordSettingKeyName, value)) { Save(); } } } }}

转载地址:http://saowo.baihongyu.com/

你可能感兴趣的文章
Facebook 宕机事故系服务器配置问题导致
查看>>
谈一个技术的问题:oracle中sql语句的优化
查看>>
在 MaxCompute UDF 中运行 Scipy
查看>>
那些阿里的年轻人
查看>>
Kafka Streams 剖析
查看>>
TortoiseSVN客户端使用教程
查看>>
卖VR眼镜需谨慎,已经有30多人因传播VR小黄片被抓了
查看>>
使用unisphere添加nas过程
查看>>
【看图识算法】这是你见过最简单的 “算法说明书”
查看>>
Oracle12C—用户概要文件profile日常操作
查看>>
ImportError: No module named items
查看>>
Oracle中可被并行化执行的SQL操作
查看>>
目标管理的感悟
查看>>
getopt_long的用法
查看>>
Ruby 数组操作
查看>>
linux系统日志
查看>>
tinyxml 用法
查看>>
MySQL数据库性能优化之存储引擎选择
查看>>
网络部署Xenserver6.5
查看>>
8.使用Xshell5密钥登录liunx
查看>>