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

查看:1336
本文介绍了如何在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?

推荐答案

您必须引用GAC中的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

请参阅 Msdn 了解更多信息

希望它有帮助!

Cédric

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

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