3

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.

James Joshua Street
  • 3,259
  • 10
  • 42
  • 80
  • 1
    Layout caculations always become tricky when manipulating UI elements in code behind, But you could attach a PropertyChanged event to the AxisDivision DependancyProperties metadata – sa_ddam213 Aug 23 '13 at 03:06

1 Answers1

2

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.

user983663
  • 46
  • 5