title: How to initialize a collection property in a custom WPF control
body: <p>I have a custom WPF control base class. This base class registers a custom property with the type "List&lt;"some own type">".</p>
  
  <p>How can I initialize the property for design time? There should always be 8 objects in the list and the user should by able to modify this objects. </p>
  
  <p>I have tried to pass a default value with the PropertyMetadata object, but the collection shown in the property editor is always empty.</p>
  
  <pre><code>public class CustomPropertyTestBase : UserControl
  {
  
      static CustomPropertyTestBase()
      {
          List&lt;object&gt; defaultValue = new List&lt;object&gt;(new object[8]);
          MyCustomObjectsProperty = DependencyProperty.Register("MyCustomObjects",
              typeof(List&lt;object&gt;), typeof(CustomPropertyTestBase),
              new PropertyMetadata(defaultValue));
      }
  
      public static DependencyProperty MyCustomObjectsProperty;
  
      [Category("MyCustomProperties")]
      public List&lt;object&gt; MyCustomObjects
      {
          get;
          set;
      }
  }
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>Whenever i add a new object in the property editor, these new objects are not stored. After reopening the property editor the list is empty again.</p>
  
  <p>I have attached the debugger to the designer and the get or set methods of the property are never called by the editor.</p>
  
  <p>SOLUTION:</p>
  
  <p>As "dowhilefor" had mentioned. I had to change the type ObservableCollection. Now the designer stores the changed list correctly.
  Thanks.</p>