Windows Phone 7 上的 App.config?
各位, 我正在 Windows Phone 7 上构建一个应用程序。我的应用程序需要一些配置,例如 Web 服务 URL、数据库名称...这些配置可能在部署期间需要时随时更改(但我不想重新构建应用)。在WPF应用程序中,我经常将这些配置保存在App.config文件中,但在WP7应用程序中我不能。
如果您以前遇到过这个问题并且有任何解决方案,请告诉我。
非常感谢。
阮平.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
WP7 不支持与桌面 .NET 应用程序相同的
app.config
文件概念。相反,如果您需要为应用程序提供基本配置信息,通常可以将常量和属性 getter 存储在 App.xaml.cs 文件中。
然后,您可以通过从应用程序中的任何位置将 Application.Current 转换为 App 来获取这些属性。
其他选项包括
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.
Other options include
我不清楚您的问题,但是:
如果您想要可以在运行时(部署后)更改的设置,请将此信息存储在
IsolatedStorage
中。您可以使用IsolatedStorageFile 或IsolatedStorageSettings,具体取决于最适合您的数据的内容。我通过在代码中设置默认设置来完成很多工作,我在第一次运行应用程序时将其写入isolatedStorageFile。然后可以根据需要读取和更新这些内容。
如果您只想在构建时更改值,请将设置包含在资源 (.resx) 文件中。
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.