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.