Class GraphController
Main MVC controller. The view type is based on an interface in function of platform independence.
Inheritance
Inherited Members
Namespace: Telerik.Windows.Diagrams.Core
Assembly: Telerik.WinControls.RadDiagram.dll
Syntax
public sealed class GraphController : IControllerService, ISerializable
Constructors
GraphController(IGraphInternal, IContainerGeneratorInternal)
Initializes a new instance of the GraphController class.
Declaration
public GraphController(IGraphInternal graph, IContainerGeneratorInternal containerGenerator)
Parameters
IGraphInternal
graph
The graph internal. |
IContainerGeneratorInternal
containerGenerator
The container generator. |
Properties
ServiceLocator
Gets the service locator.
Declaration
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
public void ActivateTool(MouseTool mouseTool)
Parameters
MouseTool
mouseTool
The mouse tool type to activate (pointer, connector, pan, pencil, path, or text tool). |
AddConnection(IConnection, Boolean)
Adds the connection.
Declaration
public void AddConnection(IConnection connection, bool isUndoable = true)
Parameters
IConnection
connection
The connection. |
System.Boolean
isUndoable
If set to |
AddShape(Object, Boolean)
Adds the shape.
Declaration
public IShape AddShape(object item, bool isUndoable = true)
Parameters
System.Object
item
The item. |
System.Boolean
isUndoable
If set to |
Returns
IShape
|
Exceptions
System.ArgumentNullException
If the item is null. |
AddShape(IShape, Boolean)
Adds the shape.
Declaration
public void AddShape(IShape shape, bool isUndoable = true)
Parameters
IShape
shape
The shape. |
System.Boolean
isUndoable
If set to |
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
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. |
System.Collections.Generic.IEnumerable<IShape>
shapes
The collection of shapes to align according to the specified alignment direction. |
BringForward(IEnumerable<IDiagramItem>, Boolean)
Brings the specified diagram items forward by one level in the Z-order drawing hierarchy with optional undo/redo support.
Declaration
public void BringForward(IEnumerable<IDiagramItem> items, bool isUndoable = true)
Parameters
System.Collections.Generic.IEnumerable<IDiagramItem>
items
The collection of diagram items to move forward one level in the drawing order. |
System.Boolean
isUndoable
True to make this operation undoable and add it to the undo/redo history; false to change Z-order permanently. |
BringToFront(IEnumerable<IDiagramItem>, Boolean)
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
public void BringToFront(IEnumerable<IDiagramItem> items, bool isUndoable = true)
Parameters
System.Collections.Generic.IEnumerable<IDiagramItem>
items
The collection of diagram items to move to the front of the drawing order. |
System.Boolean
isUndoable
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
public void ChangeTool(string toolName)
Parameters
System.String
toolName
The name or label of the tool to activate for diagram interaction. |
Clear(Boolean)
Clears the diagram by removing all items and resetting the document to its initial state without saving the current content.
Declaration
public void Clear(bool isItemsCollectionChanging = false)
Parameters
System.Boolean
isItemsCollectionChanging
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
public void ClearConnections()
ClearShapes()
Clears all shapes from the diagram by removing each shape individually while maintaining proper cleanup procedures.
Declaration
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
public string Copy()
Returns
System.String
A string representation of the serialized diagram items that were copied to the clipboard. |
CreateConnection(IShape, IShape, Boolean)
Creates the connection.
Declaration
public IConnection CreateConnection(IShape source, IShape target, bool isUndoable)
Parameters
IShape
source
The source. |
IShape
target
The target. |
System.Boolean
isUndoable
If set to |
Returns
IConnection
|
CreateConnectionInGraphSource(IShape, IShape)
Creates the connection in graph source.
Declaration
public ILink CreateConnectionInGraphSource(IShape source, IShape target)
Parameters
IShape
source
The source. |
IShape
target
The target. |
Returns
ILink
|
CreateShapeInGraphSource(IShape)
Creates the shape in graph source.
Declaration
public object CreateShapeInGraphSource(IShape shape)
Parameters
IShape
shape
The shape. |
Returns
System.Object
|
CutItems()
Cuts the items.
Declaration
public string CutItems()
Returns
System.String
A string representation of the serialized diagram items that were cut and placed in the clipboard. |
DeleteItems(IEnumerable<IDiagramItem>, Boolean)
Deletes the specified diagram items from the diagram with optional undo/redo support for operation history tracking.
Declaration
public void DeleteItems(IEnumerable<IDiagramItem> itemsToDelete, bool isUndoable)
Parameters
System.Collections.Generic.IEnumerable<IDiagramItem>
itemsToDelete
The collection of diagram items to remove from the diagram. |
System.Boolean
isUndoable
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
public void DeselectItem(IDiagramItem deselectedItem)
Parameters
IDiagramItem
deselectedItem
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
public void Deserialize(SerializationInfo info)
Parameters
SerializationInfo
info
The SerializationInfo object containing serialized diagram data to restore. |
Implements
ForceRealization()
Forces the immediate realization of all virtualized diagram elements, making them available for layout and manipulation operations.
Declaration
public void ForceRealization()
Group(String, Boolean, IGroupable[])
Groups the specified diagram items together into a single logical unit with optional naming and undo/redo support for organizational purposes.
Declaration
public IGroup Group(string name = null, bool isUndoable = false, params IGroupable[] items)
Parameters
System.String
name
The optional name to assign to the created group for identification purposes. |
System.Boolean
isUndoable
True to make this operation undoable and add it to the undo/redo history; false to group permanently. |
IGroupable[]
items
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
public bool IsInViewport(IDiagramItem item)
Parameters
IDiagramItem
item
The diagram item to check for viewport visibility. |
Returns
System.Boolean
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
public bool KeyDown(KeyArgs e)
Parameters
KeyArgs
e
The keyboard event arguments containing key information and modifier states. |
Returns
System.Boolean
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
public bool KeyUp(KeyArgs e)
Parameters
KeyArgs
e
The keyboard event arguments containing key information and modifier states. |
Returns
System.Boolean
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
public void Layout(LayoutType type = LayoutType.Sugiyama, object settings = null)
Parameters
LayoutType
type
The layout algorithm type to apply (Sugiyama is the default hierarchical layout). |
System.Object
settings
The layout-specific settings object that configures the behavior of the chosen layout algorithm. |
See Also
Load(String)
Loads and deserializes a diagram from a serialized XML string representation, replacing the current diagram content.
Declaration
public void Load(string serializationValue)
Parameters
System.String
serializationValue
A string containing XML data representing a previously serialized diagram to load and restore. |
MergeItems(IEnumerable<IDiagramItem>, String, Boolean, 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
public IEnumerable<IDiagramItem> MergeItems(IEnumerable<IDiagramItem> items, string originId, bool usePosition = false, Point position = default(Point), Size size = default(Size))
Parameters
System.Collections.Generic.IEnumerable<IDiagramItem>
items
The collection of diagram items to merge into the current diagram. |
System.String
originId
The unique identifier of the source diagram to determine if items are being merged from the same or different diagram instance. |
System.Boolean
usePosition
True to use the specified position parameter for item placement; false to calculate position automatically. |
Point
position
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
System.Collections.Generic.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
public void MouseDoubleClick(PointerArgs e)
Parameters
PointerArgs
e
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
public void MouseDown(PointerArgs e)
Parameters
PointerArgs
e
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
public void MouseMove(PointerArgs e)
Parameters
PointerArgs
e
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
public bool MouseUp(PointerArgs e)
Parameters
PointerArgs
e
The pointer event arguments containing mouse position and button information. |
Returns
System.Boolean
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
public void Nudge(Point amount)
Parameters
Point
amount
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
public void OnGraphSourceChanged(IGraphSource source)
Parameters
IGraphSource
source
The source. |
OnItemsChanged(NotifyCollectionChangedEventArgs)
Called when Items collection changes.
Declaration
public void OnItemsChanged(NotifyCollectionChangedEventArgs e)
Parameters
System.Collections.Specialized.NotifyCollectionChangedEventArgs
e
The System.Collections.Specialized.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
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
public IEnumerable<IDiagramItem> Paste(string pasteText)
Parameters
System.String
pasteText
The serialized string representation of diagram items to paste into the current diagram. |
Returns
System.Collections.Generic.IEnumerable<IDiagramItem>
A collection of diagram items that were successfully pasted and added to the diagram. |
RemoveConnection(IConnection, Boolean)
Removes the connection.
Declaration
public void RemoveConnection(IConnection connection, bool isUndoable = false)
Parameters
IConnection
connection
The connection. |
System.Boolean
isUndoable
If set to |
RemoveShape(IShape, Boolean)
Removes the shape from the diagram.
Declaration
public void RemoveShape(IShape shape, bool isUndoable = false)
Parameters
IShape
shape
The shape to be removed. |
System.Boolean
isUndoable
If set to |
Save()
Serializes the entire diagram to an XML string representation that can be saved to storage or transmitted for later restoration.
Declaration
public string Save()
Returns
System.String
An XML string containing the serialized diagram data, or null if serialization fails. |
SelectItem(IDiagramItem, Boolean)
Selects a specific diagram item, optionally adding it to the existing selection or replacing the current selection based on the selection mode.
Declaration
public void SelectItem(IDiagramItem selectedItem, bool addToExistingSelection = false)
Parameters
IDiagramItem
selectedItem
The diagram item to select, or null to clear the current selection. |
System.Boolean
addToExistingSelection
True to add the item to the current selection; false to replace the current selection (subject to selection mode restrictions). |
SendBackward(IEnumerable<IDiagramItem>, Boolean)
Sends the specified diagram items backward by one level in the Z-order drawing hierarchy with optional undo/redo support.
Declaration
public void SendBackward(IEnumerable<IDiagramItem> itemsToSend, bool isUndoable = true)
Parameters
System.Collections.Generic.IEnumerable<IDiagramItem>
itemsToSend
The collection of diagram items to move backward one level in the drawing order. |
System.Boolean
isUndoable
True to make this operation undoable and add it to the undo/redo history; false to change Z-order permanently. |
SendToBack(IEnumerable<IDiagramItem>, Boolean)
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
public void SendToBack(IEnumerable<IDiagramItem> itemsToSend, bool isUndoable = true)
Parameters
System.Collections.Generic.IEnumerable<IDiagramItem>
itemsToSend
The collection of diagram items to move to the back of the drawing order. |
System.Boolean
isUndoable
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
public SerializationInfo Serialize()
Returns
SerializationInfo
A SerializationInfo object containing the serialized diagram data, or null if serialization fails. |
Implements
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
public void SnapShapes(IEnumerable<IShape> shapes)
Parameters
System.Collections.Generic.IEnumerable<IShape>
shapes
The collection of shapes to snap to the nearest snap points based on their current positions. |
Ungroup(Boolean, IGroup[])
Ungroups the specified group items by separating their contained elements back into individual diagram items with optional undo/redo support.
Declaration
public void Ungroup(bool isUndoable = false, params IGroup[] groups)
Parameters
System.Boolean
isUndoable
True to make this operation undoable and add it to the undo/redo history; false to ungroup permanently. |
IGroup[]
groups
The collection of group items to dissolve and separate into their constituent individual elements. |
Explicit Interface Implementations
IControllerService.BeginConnectionCreation(IConnection)
Begins the connection creation.
Declaration
ICommand IControllerService.BeginConnectionCreation(IConnection connection)
Parameters
IConnection
connection
The connection. |
Returns
ICommand
|
Implements
IControllerService.BeginShapeCreation(IShape)
Begins the shape creation.
Declaration
ICommand IControllerService.BeginShapeCreation(IShape shape)
Parameters
IShape
shape
The shape. |
Returns
ICommand
|
Implements
IControllerService.CompleteConnectionCreation(IConnection)
Completes the connection creation.
Declaration
ICommand IControllerService.CompleteConnectionCreation(IConnection connection)
Parameters
IConnection
connection
The connection. |
Returns
ICommand
|
Implements
IControllerService.CompleteShapeCreation(IShape)
Completes the shape creation.
Declaration
ICommand IControllerService.CompleteShapeCreation(IShape shape)
Parameters
IShape
shape
The shape. |
Returns
ICommand
|
Implements
IControllerService.CreateConnection(IShape, IShape)
Creates the undoable connection.
Declaration
IConnection IControllerService.CreateConnection(IShape source, IShape target)
Parameters
IShape
source
The source. |
IShape
target
The target. |
Returns
IConnection
|
Implements
IControllerService.CreateConnection(Point, Point)
Creates the undoable connection.
Declaration
IConnection IControllerService.CreateConnection(Point startPoint, Point endPoint)
Parameters
Point
startPoint
The start point. |
Point
endPoint
The end point. |
Returns
IConnection
|
Implements
IControllerService.CreateGeometryShape(ref ICommand)
Creates an undoable geometry shape.
Declaration
IGeometryShape IControllerService.CreateGeometryShape(ref ICommand command)
Parameters
ICommand
command
|
Returns
IGeometryShape
|
Implements
IControllerService.CreateTextShape()
Creates an undoable geometry shape.
Declaration
ITextShape IControllerService.CreateTextShape()
Returns
ITextShape
|