WPF: Add custom type object to Settings

Just add such code to existing Settings.cs file (Settings.settings -> View code):

		[global::System.Configuration.UserScopedSettingAttribute()]
		[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
		[global::System.Configuration.DefaultSettingValueAttribute("")]
		public List<TrapModel> Traps 
		{
			get
			{
				return ((List<TrapModel>)(this["Traps"]));
			}
			set
			{
				this["Traps"] = value;
			}
		}

Here line

[global::System.Configuration.DefaultSettingValueAttribute("")]

allows to initialize object with default value (with empty List in this case) instead of set it null

Leave a Reply