如何在Windows Phone 7中存储DatePicker的日期?

时间:2011-12-11 08:10:55

标签: c# windows-phone-7

使用this link,我存储了文本框中的设置,但是我有一个DatePicker,它不起作用,我不知道为什么!有什么想法吗?这是我的代码:

public class ApplicationSettings
{

    IsolatedStorageSettings isolatedStore = IsolatedStorageSettings.ApplicationSettings;

    public bool AddOrUpdateValue(string Key, Object value)
    {
    bool valueChanged = false;

    try
    {
    // if new value  is different, set  the new value.if (isolatedStore[Key] != value)
        {
        isolatedStore[Key] = value;
        valueChanged = true;
        }
    }
    catch (Exception)
    {
        isolatedStore.Add(Key, value);
        valueChanged = true;
    }

    return valueChanged;
    }


    public valueType GetValueOrDefault<valueType>(string Key, valueType defaultValue)
    {
    valueType value;

    try
    {
        value = (valueType)isolatedStore[Key];
    }
    catch (Exception)
    {
        value = defaultValue;
    }

    return value;
    }


    public void Save()
    {
    isolatedStore.Save();
    }



    const string TextBoxSettingKeyName = "q3";
    const string TextBoxSettingDefault = "28";
    public string TextBoxSetting
    {
    get
    {
        return GetValueOrDefault<string>(TextBoxSettingKeyName, TextBoxSettingDefault);
    }
    set
    {
        AddOrUpdateValue(TextBoxSettingKeyName, value);
        Save();
    }
    }




    const string DatePickerSettingKeyName = "q6";
    DateTime DatePickerSettingDefault = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day);

    public DateTime DatePickerSetting
    {
    get
    {
        return GetValueOrDefault<DateTime>(DatePickerSettingKeyName, DatePickerSettingDefault);
    }
    set
    {
        AddOrUpdateValue(DatePickerSettingKeyName, value);
        Save();
    }
    }


}

MainPage.xaml:

<toolkit:DatePicker x:Name="PREM" Margin="0,134,14,245" 
Value="{Binding Source={StaticResource ApplicationSettings}, Path=DatePickerSetting, Mode=TwoWay}" 
Background="{x:Null}" Foreground="White" FontWeight="Bold" Header=" " 
MouseEnter="ENTER_PREM" RenderTransformOrigin="0.5,0.5" 
HorizontalAlignment="Right" Width="180" ValueChanged="VALUECHANGED_PREM">

0 个答案:

没有答案