<ig:XamNetworkNode SelectionType="Single"/>
This topic demonstrates how to zoom in on selected nodes of the xamNetworkNode™ control.
Code Examples: Zooming in on Selected Nodes
Code Example: Single Node Zooming
Code Example: Multiple Nodes Zooming
Code Example: Zooming in on Searched Node
The xamNetworkNode control now includes an enhanced feature which allows you to zoom in on a one or more selected nodes. The control also includes the ability to zoom in on user-searched nodes.
To illustrate, consider a series of nodes labeled with the numbers 1-100. While interacting with the control the user decides to zoom in on the nodes that start with 1. The search results will include the numbers 1, 11, 12, 13, 14, 15, 16, 17, 18, 19 and 100. Keep in mind that many nodes may have other nodes connected to them. If the connected nodes fit in the view of the layout, they are not hidden.
Data Source
Any object that implements IEnumerable (e.g. List, Collection etc.).
To begin, please read the Getting Started with xamNetworkNode topic as this tutorial uses the code from the ‘Getting Started’ topic as a starting point.
In addition, a few properties and methods must be set and implemented in order to achieve the desired functionality.
Properties to set on xamNetworkNode:
SelectionType
Methods to call on xamNetworkNode:
ZoomSelectedNodes
ZoomNodes
This section explains the three different ways to zooming in on the nodes in xamNetworkNode control with code examples to demonstrate the use case scenarios and the screenshots of their final results.
Single node zooming requires you to set the SelectionType property to ‘Single’ in XAML or in code behind, and then call the method (in code behind) to zoom the selected node.
Set the SelectionType property.
In XAML:
<ig:XamNetworkNode SelectionType="Single"/>
In C#:
xnn.SelectionType = Infragistics.Controls.Maps.NetworkNodeSelectionType.Single;
In Visual Basic:
xnn.SelectionType = Infragistics.Controls.Maps.NetworkNodeSelectionType.Single
Call the ZoomSelectedNodes method on the xamNetworkNode control.
In C#:
xnn.ZoomSelectedNodes();
In Visual Basic:
xnn.ZoomSelectedNodes()
The following screenshot depicts the zooming in on a single node into view by clicking on a node.
Multiple nodes zooming requires to set the SelectionStyle property to ‘Multiple’ in XAML or in code behind, and then call the method (in code behind) to zoom the selected nodes.
Keep in mind that other nodes may also be in view because the selected nodes are in a Zoom-To-Fit state with the selected nodes. “Zoom-To-Fit” refers to a state where if the selected nodes have other connected nodes (which may fit in the viewable area of the NetworkNode layout) they may also be visible.
In XAML:
<ig:XamNetworkNode SelectionType="Multiple"/>
In C#:
xnn.SelectionType = Infragistics.Controls.Maps.NetworkNodeSelectionType.Multiple;
In Visual Basic:
xnn.SelectionType = Infragistics.Controls.Maps.NetworkNodeSelectionType.Multiple
Call the ZoomSelectedNodes method on the xamNetworkNode control.
In C#:
xnn.ZoomSelectedNodes();
In Visual Basic:
xnn.ZoomSelectedNodes()
The following screenshot depicts the zooming in on multiple nodes into view by clicking on multiple nodes with [Ctrl] key combination on the keyboard.
The next screenshot displays multiple nodes zooming with other nodes in view. Notice that the selected nodes for zooming are 9 and 3; however; the selected nodes have other connected nodes (2, 28 and 30), which fit in the view of the xamNetworkNode control layout, and therefore they are visible even when they are not selected for zooming.
The purpose of zooming in on searched nodes is to retrieve a specific node that may not be visible in view, or to bring a group of nodes into view. Zooming in on searched nodes requires you to gather a collection of only the desired nodes you want to show in the view port. Once you have the filtered collection of nodes, then you can tell the xamNetworkNode control to zoom to those nodes.
The xamNetworkNode control’s Search method allows you to pass in search criteria in order to narrow down to only the nodes you want to see in the view. You build the search criteria by that passing in a Predicate object into the Search method.
Once you have the list of nodes you want to zoom to, then you call the ZoomNodes method, which accepts one argument of type IEnumerable.
The following code listing demonstrates how to add nodes that match the search criteria into the SelectedNodes collection.
Step1
In C#:
foreach (var node in xnn.Search((NodeModel item) => item.Label.StartsWith("1")))
{
xnn.SelectedNodes.Add(node);
}
In Visual Basic:
For Each node As var In xnn.Search(Function(item As NodeModel) item.Label.StartsWith("1"))
xnn.SelectedNodes.Add(node)
Next
Once the appropriate nodes are selected then call the ZoomNodes method and pass in the collection of selected nodes.
Step2
In C#:
xnn.ZoomNodes(xnn.SelectedNodes);
In Visual Basic:
xnn.ZoomNodes(xnn.SelectedNodes)
Alternatively, the examples in the given scenarios bellow demonstrate how to call the Search method directly in the ZoomNodes method as a passing argument.
Using StartWith method
The following code example calls the Search method of the xamNetworkNode control, and passes the search result directly using lambda expression. The search criterion does not restrict other nodes to be in view.
Example:
If the entered characters are “12”, the node “1234” and “1200” will at least be zoomed in to view, but the nodes “2312” or “3124” may or may not be in view.
In C#:
this.xnn.ZoomNodes(xnn.Search((NodeModel n) => n.Label.StartsWith("12")));
In Visual Basic:
Me.xnn.ZoomNodes(xnn.Search(Function(n As NodeModel) n.Label.StartsWith(“12”)))
Using EndWith method.
Example:
If the entered character is “4”, the node “1234” and “1004” will at least be zoomed in to view, but the nodes “4000” or “1040” may or may not be in view.
In C#:
this.xnn.ZoomNodes(xnn.Search((NodeModel n) => n.Label.EndsWith("4")));
In Visual Basic:
Me.xnn.ZoomNodes(xnn.Search(Function(n As NodeModel) n.Label.EndsWith(“4”)))
Using Contains method.
Example:
If the entered character is “2”, any node that contains “2” in any position will be zoomed in to view, for example “2341”, “1234”, or “1002”.
In C#:
this.xnn.ZoomNodes(xnn.Search((NodeModel n) => n.Label.Contains("2")));
In Visual Basic:
Me.xnn.ZoomNodes(xnn.Search(Function(n As NodeModel) n.Label.Contains(“2“)))