How to Make a Selected Node With a UIElement

Questions & Answers

Summary

In yFiles WPF selecting a node by default disables interaction with the UIElements the node visualization consists of. This article explains why this is the default and provides ways to disable that behavior.

This article was written for an older version. It is only online as a reference for customers using this old version. The information it contains is probably out of date.

The latest information can be found in the yFiles documentation

Description

In yFiles WPF by default selected nodes that consist of interactive UIElements (TextBoxes etc.) don't react to mouse input anymore. As soon as the node gets selected, the selection indicator blocks input to the node's UIElements. This is because the rendering of the selection is done using a rectangle that has a transparent fill and all mouse input is delegated to that transparent fill by the WPF input system.

This is intentional because otherwise basic interaction like moving a selected node would not work because instead of moving the node with a mouse drag instead e.g. text would become selected because the a text box would recognize the mouse drag as a text selection gesture.

Of course there are situations when the default behavior is unwanted, so one of the following approaches should be chosen to disable that behavior

  • Disable selection rendering alltogether

    In situations where the nodes indicate their selection state using a different scheme (e.g. by changing their color) or it is not necessary to show the selection state at all, the selection rendering can be disabled completely using the SelectionIndicatorManager property of the SelectionIndicatorManager:

    graphControl.SelectionIndicatorManager.Enabled = false;
    
  • Change the default default template for rectangular selections

    yFiles WPF uses a resource to determine the brush to use by default for rectangular
    selection indicators. Simply redeclaring the resource in one of the ancestors of the graph control (or the control itself) to null gets rid of the fill:

    <Window.Resources>
      <x:Null x:Key="{x:Static y:RectangleIndicatorInstaller.SelectionTemplateKey}"/>
    </Window.Resources>
    

Categories this article belongs to:
yFiles WPF > yFiles WPF Viewer > Displaying and Editing Graphs > Styles-related Features
yFiles WPF > yFiles WPF Viewer > Displaying and Editing Graphs > User Interaction
Applies to:
yFiles WPF: 3.0, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6
Keywords:
selection - input - UIElement - mouse input - textbox - focus