visual studio -在windows phone 8.1 c#中保存数据

本文关键字:保存 数据 phone studio windows visual | 更新日期: 2023-09-27 18:02:11

我想当关闭应用程序和重新打开应用程序保存数据在应用程序…

private void Button_Click(object sender, RoutedEventArgs e)
    {

        textblock.Visibility = Visibility.Visible;
    }

我想在这段代码中添加保存数据在关闭应用程序?!

visual studio -在windows phone 8.1 c#中保存数据

是Windows Phone 8.1 RT吗?如果是,那么你可以这样做:

 var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
 if (localSettings.Values.ContainsKey("textblockVisibility"))
 {
     var value = localSettings.Values["textblockVisibility"];
     textblock.Visibility = (bool) value ? Visibility.Visible : Visibility.Collapsed;
 }
 else
 {
      var valueToSave = textBlock.Visibility == Visibility.Visible ? true : false;
      localSettings.Values.Add("textblockVisibility", valueToSave);
 }