WPF程序中的App.Config文件是我们应用程序中经常使用的一种配置文件,System.Configuration.dll文件中提供了大量的读写的配置,所以它是一种高效的程序配置方式,那么今天我就这个部分来做一次系统性的总结。
App.Config文件是系统默认的应用程序配置文件,在我们使用后进行编译时会生成“程序集名称+.exe.config”文件,其本质上也是一个XML文件,在我们的应用程序中添加应用程序配置文件后,默认生成下面的内容。
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
</configuration>
后面可以根据需要添加我们想要配置的内容,例如我们想要自定义一个section,那么我们首先需要增加一个configSections节点,然后再添加section子节点,在子节点中我们需要添加名称name 类型type等节点信息,具体配置信息如下:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="eas" type="EAS.ConfigHandler,EAS.MicroKernel"/>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</configSections>
<eas>
<objects>
<object name="MessageBus" assembly="EAS.MicroKernel" type="EAS.Sockets.Bus.SocketBus" LifestyleType="Singleton">
<property name="Url" type="string" value="socket.tcp://127.0.0.1:1000/"/>
</object>
</objects>
</eas>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
<providers>
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"></provider>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
</providers>
</entityFramework>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
</startup>
<appSettings>
<add key="AspNetAddress" value="http://192.168.3.199:8088"/>
<add key="ServerDog" value="192.168.3.199:8001"/>
<add key="DICSCtrl" value="192.168.3.100:4503"/>
<add key="BGServerDeamon" value="192.168.3.199:5915"/>
<add key="MySQLServer" value="localhost"/>
<add key="DataSimulator" value="DataRinse"/>
<!--当前软件部署的时间-->
<add key="DeploymentTime" value="20170822"/>
<add key="UnitWidth"

本文详细介绍了WPF程序中App.Config文件的使用方法,包括基本读写操作、自定义配置节点及复杂操作等内容。
最低0.47元/天 解锁文章
404





