问题
Since there is no default configuration file In a WP8 app, what is the best way to store the configuration values, e.g. WCF service URL, User Name and Password. I want these values to be available and updatable when phone restarts and app is closed.
Thanks in advance.
回答1:
You should use IsolatedStorageSettings.ApplicationSettings
.
Save a value:
IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings;
appSettings.Add("email", "someone@contoso.com");
appSettings.Save();
Load a value:
IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings;
string val = (string)appSettings["email"];
See the MSDN tutorial here: How to: Store and Retrieve Application Settings Using Isolated Storage. It is a desktop Silverlight tutorial but it works the same way in Windows Phone.
EDIT:
Using IsolatedStorageSettings.ApplicationSettings
can be problematic if your app uses background agents (thanks @RichardSzalay for the info).
If your agent only reads, IsolatedStorageSettings.ApplicationSettings
with a Mutex is recommended.
Source: Background agent best practices for Windows Phone
回答2:
I searched for many solutions, I found this one the best:
http://msdn.microsoft.com/en-us/library/ff769510(v=vs.92).aspx
Cheers
来源:https://stackoverflow.com/questions/14723166/best-way-to-store-the-configuration-values-settings-in-windows-phone-8