Universal Windows(10) Apps settings is easy. Its simple to specify as part of the build, save them to storage, get them back and modify .. I mean dead easy!
These default settings for the app are specified in the Application class. They are used when the app is first run and saved to storage on first run. If they don't exist in storage these programmed settings are used and saved.
If they exist in storage they are read from there. They are easily modified and resaved in subsequent app sessions.
Just clear them from storage and the default ones will be used for the next app instance.
You define these in the App: Application class as public static.
sealed partial class App : Application { public static string FileName= "info.txt"; public static string User= “fred@home.com” public static string Password= p@ssw0rd;
You then refer to them in code using the App. moniker
public string Login() { string user= App.User; string pwd= App.Password; login(user,pwd); }
This info is readonly as part of the app build. After deployment if you need to change these settings, a rebuild is required.
A better solution is to allow some dynamism with the app settings by storing them in the application local storage and usethem from there.
When the app is first run you copy the App.XXX setting to the app’s local storage.
The location is Windows.Storage.ApplicationData.Current.LocalSettings
Understand that Windows.Storage.ApplicationData.Current is virtual and is not available to other apps and so is secure.
private static void ResetPassword() { string pwd= App.Password; SetSetting( “Password”, pwd); } private static void SetSetting(string value, string key) { var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; localSettings.Values[key]= value; } private static string GetPassword() { if (!ApplicationData.Current.LocalSettings.Values.ContainsKey("Password")) { ResetPassword(); } return (string)(ApplicationData.Current.LocalSettings.Values["Password"]); }
ENJOY