title: WPF MeasureOverride not working for my Custom Control
body: <p>I have a custom control that is "hosted" in a custom panel (both mine).</p>
  
  <p>My custom panel has code like this:</p>
  
  <pre><code>protected override Size MeasureOverride(Size availableSize)
  {
    foreach (UIElement child in Children)
    {
       child.Measure(availableSize);
  
       // Do stuff with the Desired Size.  (This is an example)
       resultSize.Width += child.DesiredSize.Width;
       resultSize.Height = Math.Max(resultSize.Height, child.DesiredSize.Height);
  
    }
    //.. Other Measure Stuff
  }
  </code></pre>
  
  <p>All the standard controls I put in my panel work fine.  But my custom control has <code>DesiredSize</code> set to a very small width (5 pixels).  Even though it has a <code>Label</code> on it that wants at least 40 pixels to be able to show.</p>
  
  <p>So I put this code into my custom control:</p>
  
  <pre><code>protected override Size MeasureOverride(Size constraint)
  {
      var baseSize = base.MeasureOverride(constraint);
      var labelTextWidth = GetStringWidth(label.Content.ToString(), label);
  
      if (baseSize.Width == 0)
          baseSize.Width = 100;
  
      if (baseSize.Width &lt; labelTextWidth)
          baseSize.Width = labelTextWidth;
  
      return baseSize;
  }
  </code></pre>
  
  <p>This returns a <code>Size</code> that is correct.  But in my Panel's MeasureOverride, the child.DesiredSize does not reflect what I returned from my child control's MeasureOverride.</p>
  
  <p><strong>Any ideas why it would do that?  And what I can do to get it to pass my calculated Measure to the panel correctly in the DesiredSize?</strong>  (you can't just set DesiredSize.)</p>