Search
Single and Multiple Selection

Selecting and Modifying Items

In order to move or modify a diagram element, users drag its adjustment handles. Adjustment handles appear around an item when it is selected. Each handle can be dragged to perform specific transformation on the item. The appearance and behavior of modification handles can be altered by the HandlesStyle property. Depending on the value assigned to ModificationStart, those handles can also appear automatically when the mouse pointer hovers over an item.

Active Item

If only one diagram item is selected, it is considered the 'active' item. One of the items in a multiple-selection is also regarded as active; it is usually the one selected last. The active item has white modification handles drawn around it, while other items in multiple-selection have gray handles. The active item is probably the one users are most interested in while editing a diagram, and your program can update its state and user-interface according to that. Access to the active item is provided by the ActiveItem property of the Diagram class.

Multiple-Selection

Selection of diagram items in WpfDiagram is represented by an instance of the Selection class. This class provides methods to programmatically select or deselect items and properties that specify how the selection looks and behaves. A property of the Diagram class, also called Selection, exposes the items selected within the current document. Multiple items can be selected, thus moved at the same time. To programmatically add items to or remove them from the multiple-selection invoke one of the AddItem, Toggle and RemoveItem methods. The Clear method deselected all items and the Change method selects a single item, deselecting all others. Setting AllowMultipleSelection to false disables multiple-selection.

Drawing a Selection Lasso

To select multiple items, users must draw a selection lasso or rectangle with the left mouse button while holding down the CTRL key. In order to enable free-form lasso mode, set FreeFormMode to true. The MiddleButtonActions and RightButtonActions properties let you enable drawing the selection lasso using the middle or right mouse button.

Appearance

The visual style of multiple-selection is defined by the Style property of the Selection class. For example, selection might be painted as a dashed rectangle or a semi-transparent filled rectangle. Colors of the selection rectangle can be changed by setting the selection's Pen and Brush properties. Another property related to selection visualization is the diagram's SelectionOnTop, which specifies whether selected items must be painted according to their z-order position or on top of the non-selected items.

Enumerating Items

The Selection class exposes the selected items as .NET collections. The Items collection references all selected items, getting them as DiagramItem instances. The Nodes and Links collections keep references to the selected items of specific classes. Alternatively you might enumerate all items in the diagram and check their Selected property.

Automatic Selection

Setting the  SelectAfterCreate property to true automatically selects each newly created item, so users can modify it immediately.