Scroll is not working

In my application I can add a node by doable clicking a toolbox (which is not a part of the diagram).

when There are a lot of nodes in the diagram and I add a node via the toolbox (not drag&drop) the two following functions does not work:


My current result is selection of the new added node, but it is not appearing on the screen because you need to scroll down manually to see it.

How can I scroll via code ?< =“application/x-hp-chrome-agent” id=“QTP__OBJ” =“true” comid=“1487”>

The LocalView sample demonstrates calling DiagramPanel.CenterPart.

I used the

diagram.Panel.MakeVisible(node, Rect.Empty);

Exactly as the code in the LocalView sample but sometimes it doesn't work and the scroll doesn't change to the location of the node.

When I debug it I saw that in the function DoMakeVisible the code

r = part.GetElementBounds(part.VisualElement);

Return a rectangle with only width and height, the X and Y values are NaN.

Is that the reason the MakeVisible function doesn't work?

If so how do I fix it?


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.

i am adding a new node to the diagram and then i want the diagram to scroll to its location.
is there a way to tell the diagram to measured its values after i add it and before i call the MakeVisible

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:

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.

private void 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;
do you have any idea how to solve this?

When you call MakeVisible, does _nodeToMakeVisible.Bounds have the correct value?

Yes the Bounds property have the correct value

I don’t see any obvious reason how that could happen, but we’ll investigate.

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?

How do I turn off the animation? <?: prefix = o ns = "urn:schemas-microsoft-com:office:office" />

By looking at the code I think that I need to set the ZoomTime to 0 to do so.

But when I used the code:

Diagram.Panel.ZoomTime = 0;

It worked better but still sometimes it doesn't scroll to the node.

Did I turn off the animation correctly or do I need to wait for a solution from you?

Yes, that’s right:

myDiagram.TemplateApplied += (s, e) => { myDiagram.Panel.ZoomTime = 0; };