Question

I know how to display a message box only once in windows phone apps, below is the code

if (!IsolatedStorageSettings.ApplicationSettings.Contains("IsThirdLaunchDone"))
{
     MessageBox.Show("Click on '...', go to settings and select your city and country.");
     IsolatedStorageSettings.ApplicationSettings["IsThirdLaunchDone"] = true;
} 

But am trying to port the same for my windows 8 app but couldn't get it.

if (!ApplicationData.Current.LocalSettings.Containers.ContainsKey("IsThirdLaunchDone"))
{
     //MessageDialog Code goes here
     ApplicationData.Current.LocalSettings["IsThirdLaunchDone"] = true; //**Error code**
}

Error - Cannot apply indexing with [] to an expression of type 'Windows.Storage.ApplicationDataContainer'

Need help!

Was it helpful?

Solution

The error is telling you you're trying to access a value on something that does not contain values. Try something like this instead:

if (!ApplicationData.Current.LocalSettings.Values.ContainsKey("IsThirdLaunchDone"))
{
     //MessageDialog Code goes here
     ApplicationData.Current.LocalSettings.Values["IsThirdLaunchDone"] = true;
}

Note the use of Values consistently within the get and set. (instead of Containers)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top