WPF程序中的App.config文件是应用程序中经常使用的一种配置文件,System.Configuration.dll文件中提供了大量的读写的配置,是一种很高效的程序配置方式。
1、首先在工程中配置App.config文件。
1 <?xml version="1.0" encoding="utf-8" ?> 2 <configuration> 3 </configuration>
2、在App.config文件<configuration/>标签下添加<appSettings/>标签。
<appSettings> <add key ="ProductName" value ="这是我的软件"/> </appSettings>
3、在引用中添加引用System.Configuration
4、在后台中添加引用。
using System.Configuration;
5、读操作:
string MyProduct= ConfigurationManager.AppSettings["ProductName"];
6、写操作:
Configuration myconfig= ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); myconfig.AppSettings.Settings["ProductName"].Value = "suibiandadedede"; myconfig.Save();
基础操作就这么多了!