How are normal people supposed to persist settings in a Windows Phone 8 app?

前端 未结 2 689
暖寄归人
暖寄归人 2020-12-17 09:55

I\'m in the process of writing a Windows Phone 8 app, so I can capture that much sought-after 3% market share, and am having a hard time persisting user settings within the

相关标签:
2条回答
  • 2020-12-17 10:18

    Ah ha! Figured this out. I dug up the Windows Phone 7 API docs, and the legacy APIs actually still work on Windows Phone 8 as well.

    public static void Session_PersistSession(string ticket)
    {
       if (IsolatedStorageSettings.ApplicationSettings.Contains("SessionTicket"))
       {
          IsolatedStorageSettings.ApplicationSettings["SessionTicket"] = ticket;
       }
       else
       {
          IsolatedStorageSettings.ApplicationSettings.Add("SessionTicket", ticket);
       }
    
       IsolatedStorageSettings.ApplicationSettings.Save();
    }
    
    public static string Session_LoadSession()
    {
       string ticket;
       if (IsolatedStorageSettings.ApplicationSettings.TryGetValue<String>("SessionTicket", out ticket))
       {
          return ticket;
       }
    
       return null;
    }
    
    0 讨论(0)
  • 2020-12-17 10:35

    A couple of options here....

    1. LocalFolder is supported so you could serialize whatever state you want to a file there.
    2. Check out the IsolatedStorageSettings class, specifically the ApplicationSettings property

    Also this may provide a bit more context: How to preserve and restore app state for Windows Phone

    0 讨论(0)
提交回复
热议问题