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

痴心易碎 提交于 2019-12-10 23:38:25

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/18393596/wpf-if-the-children-of-a-scrollviewer-resize-will-the-scrollviewer-automaticall

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!