I have a custom control that is "hosted" in a custom panel (both mine).
My custom panel has code like this:
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
}
All the standard controls I put in my panel work fine. But my custom control has DesiredSize set to a very small width (5 pixels). Even though it has a Label on it that wants at least 40 pixels to be able to show.
So I put this code into my custom control:
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 < labelTextWidth)
baseSize.Width = labelTextWidth;
return baseSize;
}
This returns a Size that is correct. But in my Panel's MeasureOverride, the child.DesiredSize does not reflect what I returned from my child control's MeasureOverride.
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? (you can't just set DesiredSize.)