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

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

问题描述

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

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

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appsettings>
    <add key="xmlDataDirectory" value="c:	estdata"/>
  </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 privileged way to access configuration information for any type of application.

请参阅 Microsoft Docs - ConfigurationManager 课程了解更多信息.

Please see Microsoft Docs - ConfigurationManager Class for further info.

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

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