21

I was just wondering how you deal with IsolatedStorageSettings in Windows Phone 8.1 SDK. For Example:

IsolatedStorageSettings.ApplicationSettings.Contains("LocationConsent")

How does this work in 8.1? As in, how do I write this statement without getting context errors. I feel like it's been deprecated or something because it does not resolve to a known namespace or anything.

I am working with maps for my current project and porting it to 8.1 gives me some syntax trouble. I have tried looking it up but I think it's too soon for documentation I guess because MSDN doesn't even say anything about it, unless I missed it by accident. Any help is appreciated.

Failsafe
  • 750
  • 2
  • 7
  • 23
  • What else are you expecting them to tell you beside that this method returns a boolean ? http://msdn.microsoft.com/en-us/library/cc614991(v=vs.95).aspx – aybe Apr 16 '14 at 22:36
  • 1
    I am wondering how to use that same statement in the new SDK without getting errors. The current one doesn't resolve to a namespace, so it must be deprecated or something, like they changed it. – Failsafe Apr 16 '14 at 22:49
  • I've just tried and it works fine. It's in the System.IO.IsolatedStorage namespace. – aybe Apr 16 '14 at 22:51
  • Well the only thing I can use from System.IO is System.IO.Compression. – Failsafe Apr 16 '14 at 22:53
  • Not sure what's wrong on your side, here it works out of the box. That method is located in Assembly System.Windows C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\WindowsPhone\v8.0\System.Windows.dll – aybe Apr 16 '14 at 23:03
  • @Aybe I know this is a really late response but I should've mentioned when I asked this question that I was using the Windows Phone 8.1 SDK< not the Silverlight 8.1 SDK. I just reopened this question at work, looked at it, and realized my mistake. Sorry. – Failsafe Jul 31 '14 at 13:23

1 Answers1

45

Use the classes in Windows.Storage namespace. They are new for Universal Apps. If you want the data to stay always local try Windows.Storage.ApplicationData.Current.LocalSettings. However, if you wouldn't mind them been stored in roaming settings (they would be available for your app in Windows 8.1 in case you do Universal Apps) you can use Windows.Storage.ApplicationData.Current.RoamingSettings.

var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
if(localSettings.Values.ContainsKey("LocationConsent"))
   DoSomething(localSettings.Values["LocationConsent"])

or

var roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;
if(roamingSettings.Values.ContainsKey("LocationConsent"))
   DoSomething(roamingSettings.Values["LocationConsent"])

This should resolve your issue. I wrote this from the top of my head, hopefully it will work for you.

LPains
  • 942
  • 12
  • 21
  • so there is no necessity of saving the data to the storage? like I used in windows app 8 (i.e roamingSettings.save())? – Tasnim Fabiha Mar 19 '17 at 12:18
  • 1
    you actually need to: ApplicationData.Current.RoamingSettings.SaveSettingValue("key", "value"); – LPains Mar 22 '17 at 01:34
  • I don't find the SaveSettingsValue() in my code, it's giving me an error. – Tasnim Fabiha Mar 22 '17 at 05:27
  • Oh. Sorry for that. I looked over some old piece of code I had and didn't realize I was looking at an extension method. Turns out you don't need to call save. here is the content of the extension method (container is ApplicationData.Current.RoamingSettings or ApplicationData.Current.LocalSettings): container.Values[key] = value; – LPains Mar 22 '17 at 20:19
  • oh yes I thought so. Thanks for the help :) – Tasnim Fabiha Mar 23 '17 at 10:17