If the node hasn’t been measured/arranged/laid-out yet, it doesn’t make sense to try to scroll to where it is, because it doesn’t have a location yet.
You need to wait until all that has been done.
I guess you aren’t executing that code in some command event handler.
Perhaps you could do so in a LayoutCompleted event handler?
It really depends on what you are trying to do.
Do you want the diagram to first finish its layouts so that the node has its desired location?
And that might include any layout animation (which your app might not be using, but is an issue in general).
If so the general answer is to do what I suggested: call MakeVisible in a LayoutCompleted event handler.
I did what you suggested but it only fix it partially.
When i add the new node below the current location it works but when i add it above the current location it doesn’t work.
you can see it in the movie: http://tinypic.com/r/2m2i99s/5
the button add the new node after the current selected item and during the add I save the node that I want to scroll to and use it in the event handle.
privatevoid OnLayoutCompleted(object sender, DiagramEventArgs diagramEventArgs)
{
_diagram.InnerDiagram.Panel.AutoScrollDelay = _diagram.InnerDiagram.Panel.AutoScrollTime;
if (_nodeToMakeVisible != null)
{
// Scrolling to the item
_diagram.InnerDiagram.Panel.MakeVisible(_nodeToMakeVisible, Rect.Empty);
_nodeToMakeVisible = null;
}
}
I modified your sample application to add nodes alternately at the bottom and at the top of the diagram, and to call MakeVisible on the new Node in a LayoutCompleted event handler (when the Node should have the desired position).
It works nearly every time. We haven’t figured out what the problem is yet.
When I turned off scroll animation, it always works – I have been unable to reproduce the problem. So as a work-around for now, you can just turn off scroll animation. Or have you already done so and are still experiencing the problem?