I'm implementing a ruler control (like found in most photo editors, text editors, etc). In XAML, it's used like:
<local:Ruler ... >
<Image Source="{Binding ...}" />
</local:Ruler>
For its implementation, I derive from ContentControl, override OnRender() to draw the ruler itself, then position the child content like:
protected override Size MeasureOverride(Size availableSize)
{
ContentPresenter childElement = (ContentPresenter)VisualTreeHelper.GetChild(this, 0);
if (childElement != null) childElement.Measure(availableSize);
//Console.WriteLine("Desired Size: " + childElement.DesiredSize.Width + ", " + childElement.DesiredSize.Height);
return new Size(childElement.DesiredSize.Width, childElement.DesiredSize.Height + RulerHeight);
}
protected override Size ArrangeOverride(Size finalSize)
{
UIElement childElement = (UIElement)VisualTreeHelper.GetChild(this, 0);
if (childElement != null) childElement.Arrange(new Rect(new Point(0.0, RulerHeight), finalSize));
return finalSize;
}
This seems to be working - both the ruler and the image are presented as expected (and of course, I can replace the Image with a StackPanel containing other elements, etc).
However, as soon as I try to wrap the image in a ZoomContentControl:
<local:Ruler ... >
<actinav:ZoomContentControl IsPanPadVisible="False" IsResetViewButtonVisible="False">
<Image Source="{Binding ...}" />
</actinav:ZoomContentControl>
</local:Ruler>
...it breaks. MeasureOverride() is called repeatedly, with an ever-increasing childElement.DesiredSize.Height. Uncommenting the "WriteLine" above yields output like:
Desired Size: 584, 279
Desired Size: 584, 282
Desired Size: 584, 285
Desired Size: 584, 288
Desired Size: 584, 291
Desired Size: 584, 294
Desired Size: 584, 297
Desired Size: 584, 300
Desired Size: 584, 303
Desired Size: 584, 306
(....Indefinitely.)
Why would wrapping the content in a ZoomContentControl cause this type of infinite recursion/infinite looping-type behavior?