- Application Data: Data relevant to the application, such as app settings, or context specific information such as for example in a bus route application the location of bus stops or the collection of routes.
- User Data: for example in a fitness application that tracks exercise the exercise would be Application Data, but the values would be User Data, because they're only relevant to the user.
Let's start with our simplest option, and that is local settings, it`s ideal if you`re looking to store a simple key value pair.
private void SaveValue(string Key, Object Value, string ContainerName = "Main")
{
var roamingSettings = ApplicationData.Current.RoamingSettings;
if (roamingSettings.Values.ContainsKey(Key))
roamingSettings.Values.Remove(Key);
roamingSettings.Values.Add(new KeyValuePair<string, object>(Key, Value));
}
private object GetStoredValue(string Key, string ContainerName = "Main")
{
var roamingSettings = ApplicationData.Current.RoamingSettings;
if (roamingSettings.Values.ContainsKey(Key))
return roamingSettings.Values[Key];
return String.Empty;
}
for more complex settings you can utilize containers, now you can think of a container as a dictionary of dictionaries, so you can group settings by key.
private void SaveValue(string Key, Object Value, string ContainerName="Main")
{
var localSettings = ApplicationData.Current.LocalSettings.CreateContainer(ContainerName, ApplicationDataCreateDisposition.Always);
if
(localSettings.Values.ContainsKey(Key))
localSettings.Values.Remove(Key);
localSettings.Values.Add(new KeyValuePair<string, object>(Key, Value));
}
private object GetStoredValue(string Key, string ContainerName = "Main")
{
var localSettings = ApplicationData.Current.LocalSettings;
if (localSettings.Containers.ContainsKey(ContainerName)
&& localSettings.Containers[ContainerName].Values.ContainsKey(Key))
return localSettings.Containers[ContainerName].Values[Key];
return String.Empty;
}
private void SaveValue(string Key, Object Value, string ContainerName = "Main")
{
var roamingSettings = ApplicationData.Current.RoamingSettings.CreateContainer(ContainerName, ApplicationDataCreateDisposition.Always);
if (roamingSettings.Values.ContainsKey(Key))
roamingSettings.Values.Remove(Key);
roamingSettings.Values.Add(new KeyValuePair<string, object>(Key, Value));
}
private object GetStoredValue(string Key, string ContainerName = "Main")
{
var roamingSettings = ApplicationData.Current.RoamingSettings;
if (roamingSettings.Containers.ContainsKey(ContainerName)
&& roamingSettings.Containers[ContainerName].Values.ContainsKey(Key))
return roamingSettings.Containers[ContainerName].Values[Key];
return String.Empty;
}