Hi,
How do we check if a NetworkNodeNode in a XamNetworknode is in view?
How to scroll the node into view if it is not in the the current viewing area?
Any suggestions please.
Thanks,
Prasad
Hello Prasad,
You can get a node coordinates using it’s Location property. Then add it in the selected nodes collection and compare the coordinates with the visible world rectangle area. If the node meets your criteria, ZoomSelectedNodes method should be called to bring the node into view. Here is a code snippet you can use as basis:xnn.SelectedNodes.Clear(); NetworkNodeNode node1 = xnn.Search((NodeModel item) => item.Label.StartsWith((listBox1.SelectedItem as NodeModel).Label)).FirstOrDefault(); xnn.SelectedNodes.Add(node1); if ((node1.Location.X > xnn.WorldRect.Left) && (node1.Location.X < xnn.WindowRect.Right) && (node1.Location.Y > xnn.WindowRect.Top) && (node1.Location.Y < xnn.WorldRect.Bottom)) { MessageBox.Show("Node is in view"); } else { xnn.ZoomSelectedNodes(); }I hope this will be helpful for you.
Hi Maria,
Thank you very much. The sample code helped me with little tweaking in the condition.
Earlier I am working with similar approach where I am using { Left (0), Right (xnn.ActualWidth), Top (0), Bottom (xnn.ActualHeight) } to check borders of xnn which didn't work for me.
Using WorldRect.Left & WorldRect.Bottom is not giving the desired result. The below condition worked for me:
if((node.Location.X < xnn.WindowRect.Left) || (node.Location.X + selectedNode.Control.Width > xnn.WindowRect.Right) || (node.Location.Y < xnn.WindowRect.Top) || (node.Location.Y + selectedNode.Control.Height > xnn.WindowRect.Bottom))
{
//Logic to zoom the node ...
}
I am zooming the required nodes and then setting the zoom level back to original to retain zoom level as is.
But zooming nodes is looking a bit odd as it always adjusts the window rectangle so that zoomed nodes appear in the center. For example if a node is in corner of window rectangle and then suddenly bringing it into center by sooming it is looking odd.
Is there a way to do panning through code? So that I can adjust the window rectangle such the the required node is just brought into view with a little pann movement instead of completely getting it to center of view. Also can you explain me the concept of WorldRect?