原文:《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】