App.config on windows phone 7?

这一生的挚爱 提交于 2019-12-07 01:48:36

问题


Dear all, I am building an application on windows phone 7. My application needs some configurations such as Web-service Urls, database name, ... These configurations may be changed whenever needed during deployment time ( but I don't want to re-build the application). In WPF application, I often save these configurations at App.config file, but in WP7 application I can't.

If you met this problem before as well as you have any solution for it, please tell me.

Thanks so much.

Binh Nguyen.


回答1:


I'm not clear from your question but:

If you want settings that you can change at run time (once deployed) then store this information in IsolatedStorage. You can use an IsolatedStorageFile or IsolatedStorageSettings depending on what is most appropriate to your data.
I've done this lots by having default settings in code which I write to an IsolatedStorageFile on first run of the app. These can then be read and updated as necessary.

If you just want change the values at build time, include the settings in a/the resources (.resx) file.




回答2:


WP7 doesn't support the same concept of an app.config file like desktop .NET applications.

Instead, if you need to provide basic configuration information for an app, you can often store constants and property getters in the App.xaml.cs file.

You can then get to those properties by casting Application.Current to App from anywhere in your app.

var property = ((App) Application.Current).MyWebServiceUri;

Other options include

  • Storing an XML, JSON, or INI-style data file as type Content, then opening that file and parsing it at runtime
  • Storing a resource file, parsing at runtime.


来源:https://stackoverflow.com/questions/5157153/app-config-on-windows-phone-7

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