.Net WinForm application that does not save a property of type List <MyClass>

I created a user control in a C # 3.5 Windows application and has a number of properties (string, int, color, etc.). They can be changed in the properties window, and the values ​​are saved without problems.

However, I created a property like

  public class MyItem
  {
       public string Text { get; set; }
       public string Value { get; set; }
  }

  public class MyControl : UserControl
  {
       public List<MyItem> Items { get; set; }
  }

The properties dialog allows me to add and remove these elements, but as soon as I close the dialog box, the entered values ​​are lost.

What am I missing? Many thanks!

+5
source share
1 answer

You need to initialize the elements so that autoflow / setter does not help you.

Try

public class MyControl : UserControl
{
    private List<MyItem> _items = new List<MyItem>();

    public List<MyItem> Items
    {
         get { return _items; }
         set { _items = value; }
    }
 }
+2
source

All Articles