title: override metadata in static constructor?
body: <p>I have a class that inherits the <code>TextBox</code> Class, call it <code>MyTextBox</code></p>
  
  <p>I'd like to redefine the default <code>Background</code> value for this class.</p>
  
  <p>So I looked for a way to do so and found a good option: call <code>BackgroundProperty.OverrideMetadata()</code></p>
  
  <p>trouble is: where can I put this?</p>
  
  <p>in the <code>App.OnStartup()</code>? Ugly and not practical, I'd like that to be in my Class's code file.</p>
  
  <p>in the Class's contructor? I get an exception: </p>
  
  <blockquote>
    <p>PropertyMetadata is already registered
    for the type 'MyTextBox'.</p>
  </blockquote>
  
  <p>(seems fine to me, I understand why I get this perfectly)</p>
  
  <p>So I looked again a found about the static constructor in C# (did not no about that earlier, what a pity)</p>
  
  <p>so here's my code:</p>
  
  <pre><code>public class MyTextBox : TextBox
  {
      static MyTextBox()
      {
          MyTextBox.BackgroundProperty.OverrideMetadata(typeof(MyTextBox), new FrameworkPropertyMetadata(App.Current.Resources["CustomBackgroundBrush"]));
      }
  }
  </code></pre>
  
  <p>now, I'm pretty happy whith this, but Microsoft isn't. Namely, when I use the code analysis feature, I get this:</p>
  
  <p><a href="http://msdn.microsoft.com/fr-fr/library/ms182275.aspx" rel="nofollow">CA1810: Initialize reference type static fields inline</a></p>
  
  <p>Hence my question: what can I do about it?</p>
  
  <ul>
  <li>ignore the warning? >> I don't like to ignore warnings</li>
  <li>move the call to the overrideMetadata method? >> I'd like to, but where?</li>
  </ul>
  
  <p>any hints welcome, thanks</p>
  
  <p><strong>Edit:</strong> I'll add that I don't fully understand why I get this warning, since I am not initializing anything per say in my static constructor, or am I?</p>