User Interaction

The input modes described in the section called “User Interaction” provide support for grouped graphs. In particular, this covers mouse gestures as well as keyboard shortcuts for modifying the hierarchy of nodes, for collapsing and expanding group nodes, and for navigating the hierarchy. This functionality is also accessible via WPF-like routed commands.

Class GraphEditorInputMode

GraphEditorInputMode directly supports grouping and ungrouping of selected nodes using keyboard shortcuts. The GroupSelectionAllowed and UngroupSelectionAllowed properties can be used to enable or disable these shortcuts.

Additionally, whether re-parenting of nodes is allowed in a grouped graph can be easily enabled or disabled by means of the ReparentNodesAllowed property. Fine-grained control over re-parenting, depending, for example, on the involved node to be re-parented and its new group node, can be achieved by setting a custom implementation of interface IReparentNodeHandler with the ReparentNodeHandler property.

Example 5.8, “Customizing the re-parenting gesture” illustrates an IMapper-based scheme of a custom re-parenting gesture.

Example 5.8. Customizing the re-parenting gesture

protected virtual IInputMode CreateEditorMode(IGraph graph) {
  return new GraphEditorInputMode {
      ReparentNodeHandler = new MyReparentNodeHandler()

public class MyReparentNodeHandler : ReparentNodeHandler {
  // Only re-parent, if the new group node allows so.
  public override bool IsValidParent(IInputModeContext context,
                                     INode node, INode newParent) {
    var graph = context.GetGraph();
    if (graph != null) {
      var validReparentTarget =
          graph.MapperRegistry.GetMapper<INode, bool>("validReparentTarget");
      if (validReparentTarget != null) {
        return validReparentTarget.GetValue(newParent);
    return false;

By default, GraphEditorInputMode allows re-parenting of all nodes in a grouped graph. It recognizes the re-parenting mouse gesture when the Control key is pressed while moving nodes.

Folding Support

Collapsing and expanding of selected group nodes in a folding-enabled graph is handled by GraphEditorInputMode via the support for WPF-like routed commands CollapseGroupCommand, ExpandGroupCommand, and ToggleGroupStateCommand in its NavigationInputMode.

Class NavigationInputMode

Class NavigationInputMode supports collapsing and expanding of selected group nodes in a folding-enabled graph via WPF-like routed commands. The CollapsingGroupsAllowed and ExpandingGroupsAllowed properties can be used to enable or disable these commands.

The corresponding command bindings in NavigationInputMode handle the CollapseGroupCommand, ExpandGroupCommand, and ToggleGroupStateCommand defined in class GraphCommands.

NavigationInputMode furthermore provides convenient access to IFoldedGraph's functionality for collapsing or expanding group nodes by means of the following methods:

Collapsing and expanding can also be controlled on a per-group node basis by overriding the following predicate methods:

Navigation in a hierarchy, i.e., entering group nodes or exiting the current group node, is supported by NavigationInputMode through WPF-like routed commands also. The EnteringGroupsAllowed and ExitingGroupAllowed properties can be used to enable or disable these navigation facilities.

The corresponding command bindings in NavigationInputMode handle the EnterGroupCommand, and ExitGroupCommand defined in class GraphCommands.

Controlling navigation on a per-group node basis can be achieved by using the following methods. In particular, for complete customization of the behavior, the predicate methods can be easily overridden.

void EnterGroup(INode groupNode)
void ExitGroup()
Description Methods for navigating the hierarchy of nodes.
protected virtual bool ShouldEnterGroup(INode groupNode)
protected virtual bool ShouldExitGroup()
Description Predicate methods for customization.

Class GraphCommands

GraphCommands provides a number of graph hierarchy-related commands that can be used for WPF-like command binding.

These commands rely on a commanding infrastructure very similar in concept and usage to that present in Windows Presentation Foundation. The classes that make up this support are CommandManager, CommandBinding, and RoutedCommand from the yWorks.Support.Windows namespace. Together, they realize the command pattern and the necessary command binding support for WPF-like commands in yFiles for Silverlight.

Table 5.5. GraphCommands's graph hierarchy-related commands

Command Name Description
GroupSelectionCommand Creates a new group node that contains all currently selected nodes.
UngroupSelectionCommand Regroups all currently selected nodes from their respective group nodes to under the hierarchy of nodes's root element.
AdjustGroupNodeSizeCommand Changes the size of all currently selected group nodes such that they enclose their respective contents using minimum margins. Supports a command parameter that can be of type INode or type IEnumerable<INode>.
CollapseGroupCommand Collapses all currently selected group nodes. Supports a command parameter of type INode.
ExpandGroupCommand Expands all currently selected collapsed group nodes. Supports a command parameter of type INode.
ToggleGroupStateCommand Collapses all currently selected group nodes, respectively expands all currently selected collapsed group nodes. Supports a command parameter of type INode.
EnterGroupCommand Displays the contents of a given group node in the current GraphControl. Supports a command parameter of type INode.
ExitGroupCommand Switches from displaying the contents of a group node to displaying the contents of the group node's parent level in the current GraphControl.

Note that commands that support a command parameter allow to specify a group node (or a set of group nodes) to be used instead of the current selection.

By default, these commands are used for WPF-like command binding by class GraphEditorInputMode which binds them upon installation.