title: c# - How to set default values of custom controls for wpf designer?
body: <p>How do I set default values for my custom wpf components?
  I have a Textfield with the property "public Protection Protection{set;get;}". Protection is an enum: </p>
  
  <pre><code>public class Field3270Attributes{
      public enum Protection
      {
          PROTECTED,
          UNPROTECTED,
          AUTOSKIP
      }
  }
  </code></pre>
  
  <p>The default value should be autoskip but protected is listed as the default value in the wpf designer since its the first element in the enum.
  Setting the protection in the Textfield constructor did not help. 
  I've tried DependencyProperty which does work but I have to specify a callback(setProtection) if I want any values except the default value to work.
  If I dont specify a callback, changing values inside the wpf designer has no effect.
  Is there a way to get the same behavior without having to specify callback methods for every property?</p>
  
  <pre><code>public class Textfield{
  
      public static readonly DependencyProperty ProtectionProperty =
              DependencyProperty.Register("Protection",
                                          typeof(Field3270Attributes.Protection),
                                          typeof(Textfield3270),
                                          new FrameworkPropertyMetadata(Field3270Attributes.Protection.PROTECTED, setProtection));
  
      private static void setProtection(object sender, DependencyPropertyChangedEventArgs e)
      {
          Textfield field = (Textfield)sender;
          field.Protection = (Field3270Attributes.Protection)e.NewValue;
      }
  
      private Field3270Attributes.Protection protection;
  
      public Field3270Attributes.Protection Protection
      {
          get
          {
              return protection;
          }
  
          set
          {
              this.protection = value;
  
              if (value == Field3270Attributes.Protection.UNPROTECTED)
              {
                  this.IsReadOnly = false;
                  Background = Brushes.White;
              }
              else
              {
                  this.IsReadOnly = true;
                  Background = Brushes.LightSteelBlue;
              }
          }
      }
  
      public Textfield3270()
      {
  
          this.Protection = Field3270Attributes.Protection.PROTECTED;
      }
  
  }
  </code></pre>