windows phone 8.1 - c#接受按钮
本文关键字:按钮 phone windows | 更新日期: 2023-09-27 18:01:18
我正在为Windows phone 8.1构建一个通用应用程序。
我有一个设置页面,那里只有一个拨动开关。我想知道如何保存拨动开关状态。也是在应用程序关闭和再次打开后。
我是这样尝试的:
private void Button_Click(object sender, RoutedEventArgs e)
{
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
if (!settings.Contains(TSwitch.IsOn))
{
settings.Add(TSwitch.IsOn);
}
settings.Save();
this.Frame.Navigate(typeof(MainPage), null);
}
试试这个:
private void Button_Click(object sender, RoutedEventArgs e)
{
if (TSwitch.IsOn)
{
Windows.Storage.ApplicationData.Current.LocalSettings.Values["TSwitch"] = "Set";
Windows.Storage.ApplicationData.Current.LocalSettings.Values["TSwitchValue"] = "on";
}
else
{
Windows.Storage.ApplicationData.Current.LocalSettings.Values["TSwitch"] = "NotSet";
Windows.Storage.ApplicationData.Current.LocalSettings.Values["TSwitchValue"] = "off";
}
}
然后在app . example .cs中添加:
switch ((string)Windows.Storage.ApplicationData.Current.LocalSettings.Values["TSwitchValue"])
{
case "Set":
{
//Do something
break;
}
case "NotSet":
{
//Do something
break;
}
default:
{
//Do something
break;
}
}
您可以根据切换开关的要求更改大小写选项。