WPF Application Settings File

前端 未结 3 892
闹比i
闹比i 2021-02-11 08:36

I\'m writing a WPF application with C# as the code behind and I want to give the users the option to change certain settings in my application. Is there a standard for storing

3条回答
  •  醉话见心
    2021-02-11 09:06

    use ConfigurationSection class to store / retrieve settings from configuration file

    see: How to: Create Custom Configuration Sections Using ConfigurationSection

    public class ColorElement : ConfigurationElement
        {
            [ConfigurationProperty("background", DefaultValue = "FFFFFF", IsRequired = true)]
            [StringValidator(InvalidCharacters = "~!@#$%^&*()[]{}/;'\"|\\GHIJKLMNOPQRSTUVWXYZ", MinLength = 6, MaxLength = 6)]
            public String Background
            {
                get
                {
                    return (String)this["background"];
                }
                set
                {
                    this["background"] = value;
                }
            }
        }
    

提交回复
热议问题