Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF if the children of a scrollviewer resize, will the scrollviewer automatically update its extent?

So My first question is whether the scrollviewer automatically updates its extent or whether I need to call invalidate measure on scrollviewer to force it to update.

Anyway, I have a scrollviewer with a graph inside. When I use a zoom select box I want the axis division unit to change, the scrollviewer's content to change, scrollviewer to recalculate its new extent, and finally to scroll to the correct offset.

Currently I have AxisDivisionUnit as a Dependency Property that on update invalidates the contents, which then remeasures the content and redraws.

        sg.InvalidateMeasure();
        sg.UpdateLayout();
        sg.DrawSignal();

and in another class,

           AxisDivisionUnit = NewAxisDivisionUnit;

          //need to scroll to new position based on location chosen with zoombox
          //calculate position of originalOffsetinTimescaleunits on new scale.
          double NewNumberOfPixelsPerUnit = (double)(NUMBER_OF_DEVICE_INDEP_PIXELS_PER_INCH) / AxisDivisionUnit;
          double NewPixelOffset = HorizontalUnitOffset * NewNumberOfPixelsPerUnit;
          if (NewPixelOffset > sv.ExtentWidth)
          {
            NewPixelOffset = sv.ExtentWidth - sv.ViewportWidth;
          }
          sv.ScrollToHorizontalOffset(NewPixelOffset);

However, The scrollviewer extent has not updated by the time I wish to scroll, so the code doesn't function as I wish. I guess I could also potentially call invalidatemeasure on the scrollviewer here, but then how do i ensure that the AxisDivision has changed? I need to ensure that since the size of the content depends on the property.

like image 486
James Joshua Street Avatar asked Jan 30 '26 10:01

James Joshua Street


1 Answers

Hi I had the same trouble and I fixed it by calling updateLayout method of scrollviewer control before check scrollviewer.extent property.

I hope it helps.

like image 56
user983663 Avatar answered Feb 02 '26 03:02

user983663



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!