title: Why is OverrideMetadata not responding?
body: <p>Simple question. I've subclassed <code>StackPanel</code> as you can see below. I'm trying to change it's default for <code>Grid.IsSharedSizeScopeProperty</code> to <code>true</code> since the default behavior should have that set.</p>
  <p>As you can see, I tried overriding the property in the static initializer, but it's not reflecting in the UI. However, if I instead explicitly set it in the instance constructor, it works!</p>
  <p>My question is why is the default being overridden not affecting the layout but the explicit setting of it does?</p>
  <p>Here's my XAML...</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;c:LabeledStackPanel&gt;
  
      &lt;Grid&gt;
  
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition Width=&quot;Auto&quot; SharedSizeGroup=&quot;Label&quot; /&gt;
              &lt;ColumnDefinition Width=&quot;*&quot; /&gt;
          &lt;/Grid.ColumnDefinitions&gt;
  
          &lt;TextBlock Text=&quot;Short: &quot; TextAlignment=&quot;Right&quot; /&gt;
          &lt;TextBox Grid.Column=&quot;1&quot; /&gt;
  
      &lt;/Grid&gt;
  
      &lt;Grid&gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition Width=&quot;Auto&quot; SharedSizeGroup=&quot;Label&quot; /&gt;
              &lt;ColumnDefinition Width=&quot;*&quot; /&gt;
          &lt;/Grid.ColumnDefinitions&gt;
  
          &lt;TextBlock Text=&quot;Medium-size: &quot; TextAlignment=&quot;Right&quot; /&gt;
          &lt;TextBox Grid.Column=&quot;1&quot; /&gt;
  
      &lt;/Grid&gt;
  
      &lt;Grid&gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition Width=&quot;Auto&quot; SharedSizeGroup=&quot;Label&quot; /&gt;
              &lt;ColumnDefinition Width=&quot;*&quot; /&gt;
          &lt;/Grid.ColumnDefinitions&gt;
  
          &lt;TextBlock Text=&quot;Really long size: &quot; TextAlignment=&quot;Right&quot; /&gt;
          &lt;TextBox Grid.Column=&quot;1&quot; /&gt;
  
      &lt;/Grid&gt;
      
  &lt;/c:LabeledStackPanel&gt;
  
  </code></pre>
  <p>Trying to change the default for the property.  This does not work...</p>
  <pre><code>public class LabeledStackPanel : StackPanel {
  
      static LabeledStackPanel(){
  
          Grid.IsSharedSizeScopeProperty.OverrideMetadata(
              typeof(LabeledStackPanel),
              new FrameworkPropertyMetadata(true));
      }
  }
  </code></pre>
  <p>But this does (so I know the property itself properly affects the layout):</p>
  <pre><code>public class LabeledStackPanel : StackPanel {
  
      public LabeledStackPanel(){
          Grid.SetIsSharedSizeScope(this, true);
      }
  }
  </code></pre>
  <p>Ironically, doing both doesn't work either!  This one really has me stumped!  It's as if trying to set the default somehow breaks the behavior entirely.</p>
  <pre><code>public class LabeledStackPanel : StackPanel {
  
      static LabeledStackPanel(){
  
          Grid.IsSharedSizeScopeProperty.OverrideMetadata(
              typeof(LabeledStackPanel),
              new FrameworkPropertyMetadata(true));
      }
  
      public LabeledStackPanel(){
          Grid.SetIsSharedSizeScope(this, true);
      }
  }
  </code></pre>
  <p>So what am I missing here?</p>
  <p>My guess is it may have something to do with the following comment <a href="https://docs.microsoft.com/en-us/dotnet/api/system.windows.controls.grid.issharedsizescope?view=net-5.0" rel="nofollow noreferrer">from here</a> (although this isn't a template):</p>
  <blockquote>
  <p>Grid size sharing does not work if IsSharedSizeScope is set to true within a resource template, and a SharedSizeGroup is defined outside of that template.</p>
  </blockquote>
  <p>For the record, I have also tried using <code>AddOwner</code> to redefine the property that way, but same thing. Doesn't work.</p>