title: Style: BasedOn and DefaultStyleKeyProperty.OverrideMetadata
body: <p>When I create a custom control in Visual Studio a static constructor is added automatically:</p>
  
  <pre><code>static MyListBoxItem()
   {
       DefaultStyleKeyProperty.OverrideMetadata(typeof(MyListBoxItem), new FrameworkPropertyMetadata(typeof(MyListBoxItem)));
   }
  </code></pre>
  
  <p>The Style</p>
  
  <pre><code>&lt;Style TargetType="{x:Type c:MyListBoxItem}"&gt;
    &lt;Style.Resources&gt;
       &lt;!--SelectedItem with focus--&gt;
       &lt;SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Red" /&gt;
   &lt;/Style.Resources&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p>then gives an empty layout. Without the code in the static constructor the layout is correct. As long as you do not set <code>OverridesDefaultStyle</code> to true.</p>
  
  <p>When I add  <code>BasedOn="{StaticResource {x:Type ListBoxItem}}"</code> to the Style the layout is correct with and without the static constructor code. <code>OverridesDefaultStyle</code> has no effect anymore.</p>
  
  <p>I would prefer that the style of a custom control defaults to the style of the base type.
  It looks to me as if the code in the static constructor can be omitted.<br>
  But why then is it generated by default?</p>