如何在wp 8.1中使用隔离存储

时间:2015-07-12 15:53:53

标签: c# silverlight windows-phone-8.1

如何在本代码中使用 IsolatedStorage

private void Button_Click(object sender, RoutedEventArgs e)
    {
            textblock.Visibility = Visibility.Visible;

    }

我使用Windows Phone 8.1 Silverlight c#

2 个答案:

答案 0 :(得分:1)

我假设您要存储Button Control的状态。然后你可以这样做,

if(!IsolatedStorageSettings.ApplicationSettings.Contains("ButtonVisibility"))
{
    IsolatedStorageSettings.ApplicationSettings.Add("ButtonVisibility", Visibility.Visible.ToString());
}
else
{
    IsolatedStorageSettings.ApplicationSettings["ButtonVisibility"] = Visibility.Visible.ToString());
}

这适用于Windows 8和8.1。但是,如果您只定位到Windows 8.1,则可以为通用应用Windows.Storage.ApplicationData.Current.LocalSettingsWindows.Storage.ApplicationData.Current.RoamingSettings使用新课程 有关这些的详细信息,请参阅here

答案 1 :(得分:1)

尝试使用此类实现

     public class LocalSetting
{


   public LocalSetting()
   {

   }

   public void Write(string key,string value)
   {
       try
       {
           var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
           localSettings.Values[key] = value;
       }
       catch(Exception)
       {
           MessageDialog msgbox = new MessageDialog("Erreur d'ecriture");
           msgbox.ShowAsync();
           return;

       }


   }

   public String Read(string key)
   {
       try
       {
       var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
       if(localSettings.Values.Keys.Contains(key))

      return localSettings.Values[key].ToString();
       else 
      return "";



         }
       catch(Exception)
       {
           MessageDialog msgbox = new MessageDialog("Erreur de lecture");
           msgbox.ShowAsync();
           return "";

       }
   }



}