Question

ZoomContentControl: Infinitely calling MeasureOverride?

Posted 2 years ago by Avatar Justin Klein

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?


Comments (2)

Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA

Hi Justin,

I'm sorry you are having trouble.  We looked through the code but nothing stands out as something that would cause this.  If you'd like us to look into it further, please make a new simple sample project that shows the issue and email that to our support address.  Reference this thread in your email and be sure to rename the .zip file extension of what you send so it doesn't get spam blocked.


Actipro Software Support
Posted 2 years ago by Justin Klein

Hi there,

Thanks for the reply.  I was able to 'bandaid' the issue by just wrapping the ZoomContentControl in a Grid.  The following works:

<local:Ruler ...>
    <Grid>
        <actinav:ZoomContentControl IsPanPadVisible="False" IsResetViewButtonVisible="False">
            <Image Source="{Binding ...}" />
        </actinav:ZoomContentControl>
    </Grid>
</local:Ruler>

 While this breaks (as per above):

<local:Ruler ...>
        <actinav:ZoomContentControl IsPanPadVisible="False" IsResetViewButtonVisible="False">
            <Image Source="{Binding ...}" />
        </actinav:ZoomContentControl>
</local:Ruler>

Not really the root cause of the problem, but it gets things running so I'm satisfied enough :)

Information The latest build of this product (2018.1 build 0671) was released 17 days ago, which was after the last post in this thread.

Add a Comment

Please log in to a validated account to post comments.