OnRenderSizeChanged
(
SizeChangedInfo sizeInfo
)
{
AssertValid();
// Note that this method gets called when the layout transform is
// modified, not just when the control is resized.
#if TRACE_LAYOUT_AND_DRAW
Debug.WriteLine("NodeXLControl: OnRenderSizeChanged(),"
+ " sizeInfo.NewSize = " + sizeInfo.NewSize);
#endif
base.OnRenderSizeChanged(sizeInfo);
if (sizeInfo.NewSize.Width == 0 || sizeInfo.NewSize.Height == 0)
{
// The control is in an intermediate state. Its size will
// eventually stabilize to a non-empty rectangle.
#if TRACE_LAYOUT_AND_DRAW
Debug.WriteLine("NodeXLControl: OnRenderSizeChanged() skipped");
#endif
return;
}
// The next block is an ugly workaround for the following problem.
//
// The center of the graph zoom should initially be placed at the
// center of the control, so that if the zoom is first increased via
// the GraphZoom property, the control will zoom from the center. (If
// the zoom is first increased via the mouse wheel, the zoom center
// will be placed at the mouse location.) This can't be done until the
// final control size is known.
//
// A Loaded handler would be a logical place to do this, but the final
// control size is not always available during the Loaded event,
// depending on how the control is anchored or docked within its
// parent.
//
// A workaround would be to set this control's RenderTransformOrigin to
// (0.5, 0.5) when the transforms are first created, but the control's
// transforms are designed to work with this property left at its
// default value of the origin.
//
// TODO: Fix this!
if (!m_bGraphZoomCentered && this.IsLoaded)
{
m_bGraphZoomCentered = true;
CenterGraphZoom();
}
if (m_eLayoutState != LayoutState.Stable)
{
// The new size will be detected by the LayoutState.LayoutCompleted
// case in OnRender().
return;
}
// Make sure the size has actually changed. This event fires once at
// startup and should be ignored then.
System.Drawing.Rectangle oLastGraphRectangle =
m_oLastLayoutContext.GraphRectangle;
System.Drawing.Rectangle oNewGraphRectangle =
WpfGraphicsUtil.RectToRectangle( new Rect(sizeInfo.NewSize) );
if (
oLastGraphRectangle.Width != oNewGraphRectangle.Width
||
oLastGraphRectangle.Height != oNewGraphRectangle.Height
)
{
m_eLayoutState = LayoutState.TransformRequired;
LayOutOrDrawGraph();
// For the case where this method was called because the layout
// transform was modified, make sure the graph wasn't moved too
// far by the transform.
LimitTranslation();
}
}