在 Windows Phone 8 中存储配置值/设置的最佳方式 [英] Best way to store the configuration values/settings in Windows Phone 8
问题描述
由于在 WP8 应用程序中没有默认配置文件,存储配置值的最佳方式是什么,例如WCF 服务 URL、用户名和密码.我希望这些值在手机重启和应用关闭时可用和更新.
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.
提前致谢.
推荐答案
你应该使用 IsolatedStorageSettings.ApplicationSettings
.
保存值:
IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings;
appSettings.Add("email", "someone@contoso.com");
appSettings.Save();
加载一个值:
IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings;
string val = (string)appSettings["email"];
请参阅此处的 MSDN 教程:如何:使用独立存储存储和检索应用程序设置.这是一个桌面 Silverlight 教程,但它在 Windows Phone 中的工作方式相同.
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.
如果您的应用使用后台代理,则使用 IsolatedStorageSettings.ApplicationSettings
可能会出现问题(感谢 @RichardSzalay 提供信息).
Using IsolatedStorageSettings.ApplicationSettings
can be problematic if your app uses background agents (thanks @RichardSzalay for the info).
如果您的代理只读取,建议使用带有互斥锁的 IsolatedStorageSettings.ApplicationSettings
.
If your agent only reads, IsolatedStorageSettings.ApplicationSettings
with a Mutex is recommended.
这篇关于在 Windows Phone 8 中存储配置值/设置的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!