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?
I am able to get the Panning affect with the below logic. But after adjusting the Window Rectangle the connections are not appearing, only the nodes are appearing. Something need to refreshed I think.
Is there any methods like xnn.Refresh(), xnn.Invalidate(), xnn.RePaint() available so that I can call? I tried with xnn.InvalidateVisual() & xnn.InvalidateArrange() but didn't help.
bool adjust = false; double targetLeft = xnn.WindowRect.Left; double targetRight = xnn.WindowRect.Right; double targetTop = xnn.WindowRect.Top; double targetBottom = xnn.WindowRect.Bottom;
if (node.Location.X < xnn.WindowRect.Left) { targetLeft = node.Location.X; adjust = true; }
if (node.Location.X + 120 > xnn.WindowRect.Right) { targetRight = node.Location.X + 120; adjust = true; }
if (node.Location.Y < xnn.WindowRect.Top) { targetTop = node.Location.Y; adjust = true; }
if (node.Location.Y + 40 > xnn.WindowRect.Bottom) { targetBottom = node.Location.Y + 120; adjust = true; }
if(adjust) { xnn.WindowRect = new Rect(new Point(targetLeft, targetTop), new Point(targetRight, targetBottom)); //xnn.InvalidateVisual(); //xnn.InvalidateArrange(); }
Hi Prasad,
I have used the code snippet that you shared and put a sample application together. The panning seems to work as expected with version 15.1.20151.2008. You can find attached the sample application that demonstrate the behavior on my side. The connections are displayed without the need of refreshing the layout. Would you please run the sample and let me know if the behavior is different? What are the differences?
I am just checking if you had a chance to look into this and if you would like any further assistance on the matter.