Class
GraphController

Main MVC controller. The view type is based on an interface in function of platform independence.

Definition

Namespace:Telerik.Windows.Diagrams.Core

Assembly:Telerik.WinControls.RadDiagram.dll

Syntax:

cs-api-definition
public sealed class GraphController : IControllerService, ISerializable

Inheritance: objectGraphController

Implements: IControllerServiceISerializable

Constructors

GraphController(IGraphInternal, IContainerGeneratorInternal)

Initializes a new instance of the GraphController class.

Declaration

cs-api-definition
public GraphController(IGraphInternal graph, IContainerGeneratorInternal containerGenerator)

Parameters

graph

IGraphInternal

The graph internal.

containerGenerator

IContainerGeneratorInternal

The container generator.

Properties

ServiceLocator

Gets the service locator.

Declaration

cs-api-definition
public ServiceLocator ServiceLocator { get; }

Property Value

ServiceLocator

Methods

ActivateTool(MouseTool)

Activates the specified mouse tool for interaction with the diagram, changing the current primary tool based on the provided mouse tool type.

Declaration

cs-api-definition
public void ActivateTool(MouseTool mouseTool)

Parameters

mouseTool

MouseTool

The mouse tool type to activate (pointer, connector, pan, pencil, path, or text tool).

AddConnection(IConnection, bool)

Adds the connection.

Declaration

cs-api-definition
public void AddConnection(IConnection connection, bool isUndoable = true)

Parameters

connection

IConnection

The connection.

isUndoable

bool

If set to true [is undoable].

AddShape(IShape, bool)

Adds the shape.

Declaration

cs-api-definition
public void AddShape(IShape shape, bool isUndoable = true)

Parameters

shape

IShape

The shape.

isUndoable

bool

If set to true [is undoable].

AddShape(object, bool)

Adds the shape.

Declaration

cs-api-definition
public IShape AddShape(object item, bool isUndoable = true)

Parameters

item

object

The item.

isUndoable

bool

If set to true [is undoable].

Returns

IShape

Exceptions

ArgumentNullException

If the item is null.

AlignShapes(Alignment, IEnumerable<IShape>)

Aligns the specified shapes to the most left, top, right, or bottom edge defined by the selection bounds, providing precise geometric alignment control.

Declaration

cs-api-definition
public void AlignShapes(Alignment alignment, IEnumerable<IShape> shapes)

Parameters

alignment

Alignment

The alignment direction that determines whether alignment should be calculated towards left, top, right, or bottom edge.

shapes

IEnumerable<IShape>

The collection of shapes to align according to the specified alignment direction.

BringForward(IEnumerable<IDiagramItem>, bool)

Brings the specified diagram items forward by one level in the Z-order drawing hierarchy with optional undo/redo support.

Declaration

cs-api-definition
public void BringForward(IEnumerable<IDiagramItem> items, bool isUndoable = true)

Parameters

items

IEnumerable<IDiagramItem>

The collection of diagram items to move forward one level in the drawing order.

isUndoable

bool

True to make this operation undoable and add it to the undo/redo history; false to change Z-order permanently.

BringToFront(IEnumerable<IDiagramItem>, bool)

Brings the specified diagram items to the front of the Z-order by setting their Z-index above all other items with optional undo/redo support.

Declaration

cs-api-definition
public void BringToFront(IEnumerable<IDiagramItem> items, bool isUndoable = true)

Parameters

items

IEnumerable<IDiagramItem>

The collection of diagram items to move to the front of the drawing order.

isUndoable

bool

True to make this operation undoable and add it to the undo/redo history; false to change Z-order permanently.

ChangeTool(string)

Changes the active tool to the specified tool name, switching the current interaction mode for the diagram controller.

Declaration

cs-api-definition
public void ChangeTool(string toolName)

Parameters

toolName

string

The name or label of the tool to activate for diagram interaction.

Clear(bool)

Clears the diagram by removing all items and resetting the document to its initial state without saving the current content.

Declaration

cs-api-definition
public void Clear(bool isItemsCollectionChanging = false)

Parameters

isItemsCollectionChanging

bool

Indicates whether the items collection is currently being modified to prevent recursive clearing operations.

Remarks

The diagram is not saved prior to this reset. You need to handle in the application the eventual necessity to save (or request the user) the diagram before this.

ClearConnections()

Clears all connections from the diagram by removing each connection individually while maintaining proper cleanup procedures.

Declaration

cs-api-definition
public void ClearConnections()

ClearShapes()

Clears all shapes from the diagram by removing each shape individually while maintaining proper cleanup procedures.

Declaration

cs-api-definition
public void ClearShapes()

Copy()

Creates a serialized copy of the currently selected diagram items and places it in the system clipboard for later pasting operations.

Declaration

cs-api-definition
public string Copy()

Returns

string

A string representation of the serialized diagram items that were copied to the clipboard.

CreateConnection(IShape, IShape, bool)

Creates the connection.

Declaration

cs-api-definition
public IConnection CreateConnection(IShape source, IShape target, bool isUndoable)

Parameters

source

IShape

The source.

target

IShape

The target.

isUndoable

bool

If set to true [is undoable].

Returns

IConnection

CreateConnectionInGraphSource(IShape, IShape)

Creates the connection in graph source.

Declaration

cs-api-definition
public ILink CreateConnectionInGraphSource(IShape source, IShape target)

Parameters

source

IShape

The source.

target

IShape

The target.

Returns

ILink

CreateShapeInGraphSource(IShape)

Creates the shape in graph source.

Declaration

cs-api-definition
public object CreateShapeInGraphSource(IShape shape)

Parameters

shape

IShape

The shape.

Returns

object

CutItems()

Cuts the items.

Declaration

cs-api-definition
public string CutItems()

Returns

string

A string representation of the serialized diagram items that were cut and placed in the clipboard.

DeleteItems(IEnumerable<IDiagramItem>, bool)

Deletes the specified diagram items from the diagram with optional undo/redo support for operation history tracking.

Declaration

cs-api-definition
public void DeleteItems(IEnumerable<IDiagramItem> itemsToDelete, bool isUndoable)

Parameters

itemsToDelete

IEnumerable<IDiagramItem>

The collection of diagram items to remove from the diagram.

isUndoable

bool

True to make this operation undoable and add it to the undo/redo history; false to delete permanently.

DeselectItem(IDiagramItem)

Deselects a specific diagram item from the current selection, or clears the entire selection if the item is null.

Declaration

cs-api-definition
public void DeselectItem(IDiagramItem deselectedItem)

Parameters

deselectedItem

IDiagramItem

The diagram item to remove from the selection, or null to clear the entire selection.

Deserialize(SerializationInfo)

Deserializes diagram data from a SerializationInfo object and restores the diagram state, replacing current content with deserialized items.

Declaration

cs-api-definition
public void Deserialize(SerializationInfo info)

Parameters

info

SerializationInfo

The SerializationInfo object containing serialized diagram data to restore.

Implements ISerializable.Deserialize(SerializationInfo)

ForceRealization()

Forces the immediate realization of all virtualized diagram elements, making them available for layout and manipulation operations.

Declaration

cs-api-definition
public void ForceRealization()

Group(string, bool, params IGroupable[])

Groups the specified diagram items together into a single logical unit with optional naming and undo/redo support for organizational purposes.

Declaration

cs-api-definition
public IGroup Group(string name = null, bool isUndoable = false, params IGroupable[] items)

Parameters

name

string

The optional name to assign to the created group for identification purposes.

isUndoable

bool

True to make this operation undoable and add it to the undo/redo history; false to group permanently.

items

IGroupable[]

The collection of groupable diagram items to combine into a single group.

Returns

IGroup

The IGroup instance representing the newly created group containing the specified items.

IsInViewport(IDiagramItem)

Checks if the specified diagram item is currently visible within the diagram's viewport boundaries for virtualization purposes.

Declaration

cs-api-definition
public bool IsInViewport(IDiagramItem item)

Parameters

item

IDiagramItem

The diagram item to check for viewport visibility.

Returns

bool

True if the item is within the current viewport boundaries; false if it is outside the visible area.

KeyDown(KeyArgs)

Handles keyboard key down events and processes them through the active tool service for diagram interaction.

Declaration

cs-api-definition
public bool KeyDown(KeyArgs e)

Parameters

e

KeyArgs

The keyboard event arguments containing key information and modifier states.

Returns

bool

True if the key down event was handled by the tool service; otherwise, false.

KeyUp(KeyArgs)

Handles keyboard key up events and processes them through the active tool service for diagram interaction.

Declaration

cs-api-definition
public bool KeyUp(KeyArgs e)

Parameters

e

KeyArgs

The keyboard event arguments containing key information and modifier states.

Returns

bool

True if the key up event was handled by the tool service; otherwise, false.

Layout(LayoutType, object)

Organizes the diagram using the specified layout algorithm type, applying automatic arrangement and positioning of diagram elements.

Declaration

cs-api-definition
public void Layout(LayoutType type = LayoutType.Sugiyama, object settings = null)

Parameters

type

LayoutType

The layout algorithm type to apply (Sugiyama is the default hierarchical layout).

settings

object

The layout-specific settings object that configures the behavior of the chosen layout algorithm.

Load(string)

Loads and deserializes a diagram from a serialized XML string representation, replacing the current diagram content.

Declaration

cs-api-definition
public void Load(string serializationValue)

Parameters

serializationValue

string

A string containing XML data representing a previously serialized diagram to load and restore.

MergeItems(IEnumerable<IDiagramItem>, string, bool, Point, Size)

Merges the specified diagram items into the current diagram with position and size adjustments, supporting container integration and paste operations with undoable commands.

Declaration

cs-api-definition
public IEnumerable<IDiagramItem> MergeItems(IEnumerable<IDiagramItem> items, string originId, bool usePosition = false, Point position = default, Size size = default)

Parameters

items

IEnumerable<IDiagramItem>

The collection of diagram items to merge into the current diagram.

originId

string

The unique identifier of the source diagram to determine if items are being merged from the same or different diagram instance.

usePosition

bool

True to use the specified position parameter for item placement; false to calculate position automatically.

position

Point

The target position for placing merged items when usePosition is true.

size

Size

The target size constraints for merged items during the merge operation.

Returns

IEnumerable<IDiagramItem>

A collection of diagram items that were successfully merged and added to the current diagram.

MouseDoubleClick(PointerArgs)

Handles mouse double-click events by detecting the shape under the cursor and publishing shape double-click events or delegating to the tool service.

Declaration

cs-api-definition
public void MouseDoubleClick(PointerArgs e)

Parameters

e

PointerArgs

The pointer event arguments containing mouse position and button information.

MouseDown(PointerArgs)

Handles mouse button down events, processes them through the tool service, and exits edit mode for any diagram items currently being edited.

Declaration

cs-api-definition
public void MouseDown(PointerArgs e)

Parameters

e

PointerArgs

The pointer event arguments containing mouse position and button information.

MouseMove(PointerArgs)

Handles mouse move events and processes them through the active tool service for diagram interaction and cursor tracking.

Declaration

cs-api-definition
public void MouseMove(PointerArgs e)

Parameters

e

PointerArgs

The pointer event arguments containing current mouse position and movement information.

MouseUp(PointerArgs)

Handles mouse button up events, processes them through the tool service, and publishes shape or connection click events for items under the cursor.

Declaration

cs-api-definition
public bool MouseUp(PointerArgs e)

Parameters

e

PointerArgs

The pointer event arguments containing mouse position and button information.

Returns

bool

True if the mouse up event was handled by the tool service; otherwise, false.

Nudge(Point)

Nudges (applies a small translation movement) the currently selected diagram items by the specified amount using the same undoable mechanism as the dragging tool.

Declaration

cs-api-definition
public void Nudge(Point amount)

Parameters

amount

Point

The amount of translation defined as a point (vector) specifying the X and Y displacement values.

Remarks

This is an undoable action and plugs into the same mechanism as the DraggingTool.

OnGraphSourceChanged(IGraphSource)

Called when graph source changes.

Declaration

cs-api-definition
public void OnGraphSourceChanged(IGraphSource source)

Parameters

source

IGraphSource

The source.

OnItemsChanged(NotifyCollectionChangedEventArgs)

Called when Items collection changes.

Declaration

cs-api-definition
public void OnItemsChanged(NotifyCollectionChangedEventArgs e)

Parameters

e

NotifyCollectionChangedEventArgs

The NotifyCollectionChangedEventArgs instance containing the event data.

OnViewportChanged()

Handles viewport boundary changes by updating virtualization and refreshing scrollbar positions to reflect the new visible area.

Declaration

cs-api-definition
public void OnViewportChanged()

Paste(string)

Pastes diagram items from a serialized string representation, deserializing and adding them to the current diagram with position adjustments.

Declaration

cs-api-definition
public IEnumerable<IDiagramItem> Paste(string pasteText)

Parameters

pasteText

string

The serialized string representation of diagram items to paste into the current diagram.

Returns

IEnumerable<IDiagramItem>

A collection of diagram items that were successfully pasted and added to the diagram.

RemoveConnection(IConnection, bool)

Removes the connection.

Declaration

cs-api-definition
public void RemoveConnection(IConnection connection, bool isUndoable = false)

Parameters

connection

IConnection

The connection.

isUndoable

bool

If set to true [is undoable].

RemoveShape(IShape, bool)

Removes the shape from the diagram.

Declaration

cs-api-definition
public void RemoveShape(IShape shape, bool isUndoable = false)

Parameters

shape

IShape

The shape to be removed.

isUndoable

bool

If set to true the action will be recorded in the undo stack.

Save()

Serializes the entire diagram to an XML string representation that can be saved to storage or transmitted for later restoration.

Declaration

cs-api-definition
public string Save()

Returns

string

An XML string containing the serialized diagram data, or null if serialization fails.

SelectItem(IDiagramItem, bool)

Selects a specific diagram item, optionally adding it to the existing selection or replacing the current selection based on the selection mode.

Declaration

cs-api-definition
public void SelectItem(IDiagramItem selectedItem, bool addToExistingSelection = false)

Parameters

selectedItem

IDiagramItem

The diagram item to select, or null to clear the current selection.

addToExistingSelection

bool

True to add the item to the current selection; false to replace the current selection (subject to selection mode restrictions).

SendBackward(IEnumerable<IDiagramItem>, bool)

Sends the specified diagram items backward by one level in the Z-order drawing hierarchy with optional undo/redo support.

Declaration

cs-api-definition
public void SendBackward(IEnumerable<IDiagramItem> itemsToSend, bool isUndoable = true)

Parameters

itemsToSend

IEnumerable<IDiagramItem>

The collection of diagram items to move backward one level in the drawing order.

isUndoable

bool

True to make this operation undoable and add it to the undo/redo history; false to change Z-order permanently.

SendToBack(IEnumerable<IDiagramItem>, bool)

Sends the specified diagram items to the back of the Z-order by setting their Z-index below all other items with optional undo/redo support.

Declaration

cs-api-definition
public void SendToBack(IEnumerable<IDiagramItem> itemsToSend, bool isUndoable = true)

Parameters

itemsToSend

IEnumerable<IDiagramItem>

The collection of diagram items to move to the back of the drawing order.

isUndoable

bool

True to make this operation undoable and add it to the undo/redo history; false to change Z-order permanently.

Serialize()

Serializes the current diagram state into a SerializationInfo object containing all diagram data for persistence or transmission.

Declaration

cs-api-definition
public SerializationInfo Serialize()

Returns

SerializationInfo

A SerializationInfo object containing the serialized diagram data, or null if serialization fails.

Implements ISerializable.Serialize()

SnapShapes(IEnumerable<IShape>)

Snaps the specified shapes to the nearest snap points based on the current snap value, using an undoable command that supports undo/redo operations.

Declaration

cs-api-definition
public void SnapShapes(IEnumerable<IShape> shapes)

Parameters

shapes

IEnumerable<IShape>

The collection of shapes to snap to the nearest snap points based on their current positions.

Ungroup(bool, params IGroup[])

Ungroups the specified group items by separating their contained elements back into individual diagram items with optional undo/redo support.

Declaration

cs-api-definition
public void Ungroup(bool isUndoable = false, params IGroup[] groups)

Parameters

isUndoable

bool

True to make this operation undoable and add it to the undo/redo history; false to ungroup permanently.

groups

IGroup[]

The collection of group items to dissolve and separate into their constituent individual elements.