How Can Use Isolated Storage in wp 8.1

北城余情 提交于 2019-12-09 04:30:31
deeiip

I assume you want to store the state of your Button Control. Then you can do this,

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

This will work on windows 8 and 8.1. But if you target windows 8.1 only you can use new classes for Universal Apps Windows.Storage.ApplicationData.Current.LocalSettings and Windows.Storage.ApplicationData.Current.RoamingSettings For details on these see here.

Try to use this class implementation

     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 "";

       }
   }



}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!