如何使用WPF应用程序App.config文件? [英] How to use a App.config file in WPF applications?

查看:154
本文介绍了如何使用WPF应用程序App.config文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的WPF应用程序中创建一个App.config文件:

I created a App.config file in my WPF application:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appsettings>
    <add key="xmlDataDirectory" value="c:\testdata"/>
  </appsettings>
</configuration>

然后我尝试读取值了这一点:

Then I try to read the value out with this:

string xmlDataDirectory = ConfigurationSettings.AppSettings.Get("xmlDataDirectory");

但它说这是过时,我应该使用ConfigurationManager中,我都找不到,甚至搜索在类视图。

But it says this is obsolete and that I should use ConfigurationManager which I can't find, even searching in the class view.

有谁知道如何使用配置文件像这样在WPF?

Does anyone know how to use config files like this in WPF?

推荐答案

您必须引用System.Configuration组件,其在海关总署

You have to reference the System.Configuration assembly which is in GAC

使用ConfigurationManager中的不WPF具体的:它是具有优越的方式来访问配置信息用于任何类型的应用程序

Use of ConfigurationManager is not WPF specific : it is the priviledged way to access configuration information for any type of application

请参阅<一href="http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.aspx">Msdn进一步信息

希望它能帮助!

塞德里克

这篇关于如何使用WPF应用程序App.config文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆