原文:《User Settings in WPF》 Posted on 2014/04/09ide
================================================================================spa
介绍参看:How To: Write User Settings at Run Time with C#code
对于一个用户范围的值 [Length]-[ulong]-[User]-[0] 的操做xml
读取值:blog
length = Properties.Settings.Default.length;
设置并保存值:get
1 //Properties.Settings.Default["Length"] = length; 2 Properties.Settings.Default.Length = length; 3 Properties.Settings.Default.Save();
1 xmlns:prop="clr-namespace:WPFApplication1.Properties" 2 ... 3 4 <CheckBox IsChecked="{Binding Source={x:Static prop:Settings.Default},Path=CheckBoxChecked,Mode=TwoWay}"/>
在应用程序退出时保存:it
1 protected override void OnExit(ExitEventArgs e) 2 { 3 Settings.Default.Save(); 4 5 base.OnExit(e); 6 }
使用user-scope的设置会保存在系统用户目录下,好比:io
C:\Users\[UserName]\AppData\Local\[CompanyName]\[AssemblyName.exe_Url_2yf2tbfgmutxr5qlus32f2njn5tnpupf]\1.0.0.0\user.config
================================================================================编译
缺点:class
从新编译运行后会可能会生成新的配置文件,而再也不使用旧的配置数据:
【END】