UWP applications can easily store simple settings in a key/value store locally or even in the cloud so your application or a game can share settings between different user's devices.
Following data types can be used for settings:
Start by retrieving the local and/or roaming data container.
Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;
To create or write a setting, use ApplicationDataContainer.Values property to access the settings in the data container. For example lets create a local setting named FontSize
with an int
value 10
and roaming setting Username
with a string
value Bob
.
localSettings.Values["FontSize"] = 10;
roamingSettings.Values["Username"] = "Bob";
To retrieve the setting, use the same ApplicationDataContainer.Values property that you used to create the setting.
int fontSize = localSettings["FontSize"];
string username = roamingSettings["Username"];
Good practice is to check if a setting exists before retrieving it.
if (localSettings.Values.ContainsKey("FontSize"))
int fontSize = localSettings["FontSize"];
if (roamingSettings.Values.ContainsKey("Username"))
string username = roamingSettings["Username"];
Roaming settings have size quota. Use RoamingStorageQuota property go get it.
You can find more about settings, their limits and code examples on MSDN.