Ibrahim Tornado
Ibrahim Tornado

Reputation: 29

How Can Use Isolated Storage in wp 8.1

How can I Use IsolatedStorage In this Code:

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

    }

I use Windows Phone 8.1 Silverlight c#

Upvotes: 1

Views: 67

Answers (2)

Riadh Ben Hassine
Riadh Ben Hassine

Reputation: 341

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

       }
   }



}

Upvotes: 1

deeiip
deeiip

Reputation: 3379

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.

Upvotes: 1

Related Questions