Best way to store the configuration values/settings in Windows Phone 8

非 Y 不嫁゛ 提交于 2019-12-13 12:27:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!