How to : Create a Setting Page For Windows Phone

using System; using System.IO.IsolatedStorage; using System.Diagnostics; using System.Collections.Generic; namespace SettingsSample { public class AppSettings { // Our isolated storage settings IsolatedStorageSettings isolatedStore; // 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() { try { // Get the settings for this application. isolatedStore = IsolatedStorageSettings.ApplicationSettings; } catch (Exception e) { Debug.WriteLine("Exception while using IsolatedStorageSettings: " + e.ToString()); } } /// /// 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 (isolatedStore.Contains(Key)) { // If the value has changed if (isolatedStore[Key] != value) { // Store the new value isolatedStore[Key] = value; valueChanged = true; } } // Otherwise create the key. else { isolatedStore.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 valueType GetValueOrDefault(string Key, valueType defaultValue) { valueType value; // If the key exists, retrieve the value. if (isolatedStore.Contains(Key)) { value = (valueType)isolatedStore[Key]; } // Otherwise, use the default value. else { value = defaultValue; } return value; } /// /// Save the settings. /// public void Save() { isolatedStore.Save(); } /// /// Property to get and set a CheckBox Setting Key. /// public bool CheckBoxSetting { get { return GetValueOrDefault(CheckBoxSettingKeyName, CheckBoxSettingDefault); } set { AddOrUpdateValue(CheckBoxSettingKeyName, value); Save(); } } /// /// Property to get and set a ListBox Setting Key. /// public int ListBoxSetting { get { return GetValueOrDefault(ListBoxSettingKeyName, ListBoxSettingDefault); } set { AddOrUpdateValue(ListBoxSettingKeyName, value); Save(); } } /// /// Property to get and set a RadioButton Setting Key. /// public bool RadioButton1Setting { get { return GetValueOrDefault(RadioButton1SettingKeyName, RadioButton1SettingDefault); } set { AddOrUpdateValue(RadioButton1SettingKeyName, value); Save(); } } /// /// Property to get and set a RadioButton Setting Key. /// public bool RadioButton2Setting { get { return GetValueOrDefault(RadioButton2SettingKeyName, RadioButton2SettingDefault); } set { AddOrUpdateValue(RadioButton2SettingKeyName, value); Save(); } } /// /// Property to get and set a RadioButton Setting Key. /// public bool RadioButton3Setting { get { return GetValueOrDefault(RadioButton3SettingKeyName, RadioButton3SettingDefault); } set { AddOrUpdateValue(RadioButton3SettingKeyName, value); Save(); } } /// /// Property to get and set a Username Setting Key. /// public string UsernameSetting { get { return GetValueOrDefault(UsernameSettingKeyName, UsernameSettingDefault); } set { AddOrUpdateValue(UsernameSettingKeyName, value); Save(); } } /// /// Property to get and set a Password Setting Key. /// public string PasswordSetting { get { return GetValueOrDefault(PasswordSettingKeyName, PasswordSettingDefault); } set { AddOrUpdateValue(PasswordSettingKeyName, value); Save(); } } } } x:Class="SettingsSample.SettingsWithoutConfirmation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:SettingsSample" FontFamily="{StaticResource PhoneFontFamilyNormal}" FontSize="{StaticResource PhoneFontSizeNormal}" Foreground="{StaticResource PhoneForegroundBrush}" SupportedOrientations="Portrait" Orientation="Portrait" mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480" shell:SystemTray.IsVisible="True">

转载于:https://www.cnblogs.com/thankchunzi/archive/2011/12/03/2274756.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值