How to bring any node to view (visible area)


I am trying to bring specific node to visible area inside the diagram control.
Please check the scenario:
There are lot of nodes in the graph and because of that there is scrollbar displayed on the graph. I have reference of specific node. Now It may possible that the node is hidden because of scrollbar.
I want to scroll the scrollbars of the diagram control programatically so that the required node comes to the center (or in visible) area.
I had tried following but I am not able to make it work.
myDiagram.Panel.MakeVisible(node, Rect.Empty);
I found this while searching the forum.

Yes, that’s the right thing to do. Or to call:
which tries to center the node even if it’s already visible in the viewport.

So the question is when you are calling this method.
At the time you call it, the DiagramPanel.DiagramBounds needs to be what you expect, and the Node.Bounds needs to have its expected value.

But if automatic layout is involved, the position of the Node might not be known until the layout has finished.

And the DiagramBounds can’t be calculated until after the layout is finished (the LayoutManager calls DiagramPanel.UpdateDiagramBounds() automatically).

If this is the case for your app, you should call MakeVisible or CenterPart in a Diagram.LayoutCompleted event handler.

Strangely your code does not work but by hit and try I found the following code to work

       currentNode.Move(new Point(0, 0), true);

I think the original poster didn’t want to change any Node.Location (or Node.Position), but just wanted to scroll the diagram – i.e. change the DiagramPanel.Position.

For version 1.2 we have added two properties relating to trying to scroll the diagram so that a Node is centered: Diagram.InitialCenteredNodeData and Diagram.CenteredNodeData.

You can set or data-bind these values so that the diagram will find the Node corresponding to the data and then scroll so that it is either at the center of the view or as far as it can go in that direction.

As might be clear from the name, InitialCenteredNodeData just does this scrolling once, at the time of a Diagram.InitialLayoutCompleted event. CenteredNodeData is used after each layout, at the time of a Diagram.LayoutCompleted event.

What’s fun is that with data-binding, you can trivially get the diagram to automatically center the currently selected node. Just do this data-binding:

<go:Diagram x:Name="myDiagram" . . . CenteredNodeData="{Binding ElementName=myDiagram, Path=SelectedNode.Data}">
This is now done in the updated Entity Relationship sample. There is a separate ListBox showing all of the node data. Selecting one of these also selects the corresponding Node in the Diagram, which in turn causes that Node to be scrolled into view. Initially it’s rescaled so that everything fits in the view, so selecting any node won’t cause any scrolling to occur. But if you zoom in or if you manually move the nodes farther apart, then selecting an item in the ListBox will cause the corresponding Node to be scrolled into view.

Is this property available and is the 1.2 update available for customers. Seems like a really useful feature for us.

I assume you have already seen the announcement for 1.2 beta.

I expect it should be released “soon”. Still working on some bugs…