zoukankan      html  css  js  c++  java
  • User Settings in WPF

    原文:《User Settings in WPF》 Posted on 2014/04/09

    ================================================================================

    介绍参看:How To: Write User Settings at Run Time with C#

    1. 应用程序范围的设置无法在运行时更改;
    2. 用户范围的设置可以在运行时更改。

    对于一个用户范围的值 [Length]-[ulong]-[User]-[0] 的操作

    读取值:

    length = Properties.Settings.Default.length;

    设置并保存值:

    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}"/>

    在应用程序退出时保存:

    1 protected override void OnExit(ExitEventArgs e)
    2 {
    3     Settings.Default.Save();
    4 
    5     base.OnExit(e);
    6 }

    使用user-scope的设置会保存在系统用户目录下,比如:

    C:Users[UserName]AppDataLocal[CompanyName][AssemblyName.exe_Url_2yf2tbfgmutxr5qlus32f2njn5tnpupf]1.0.0.0user.config

    ================================================================================

    缺点:

    重新编译运行后会可能会生成新的配置文件,而不再使用旧的配置数据:

    【END】

  • 相关阅读:
    Array总结
    js 添加收藏
    js 浮点数
    chrome 不支持 input file cursor:pointer
    nginx proxy_set_header设置、自定义header
    docker常用命令
    ssh登录问题解决
    android10 搜索不到ble设备的问题解决
    go语言接口型函数使用
    树莓派gpio驱动
  • 原文地址:https://www.cnblogs.com/submarinex/p/3967780.html
Copyright © 2011-2022 走看看