Clipboard Commands in WPF SfDiagram

18 Nov 20183 minutes to read

Clipboard commands are used to cut or copy the selected diagram objects to the clipboard and paste the valid clipboard content onto the WPF Diagram page.

Cut command

The Cut command is used to cut the selected diagram objects to the clipboard. Cut command can be executed using the keyboard shortcut CTRL + X.

NOTE

The Cut command is applicable only when one or more diagram elements are selected. If no elements are selected, the command will not perform any operation.

<Button Height="50" Content="Cut" Name="Cut" Command="Syncfusion:DiagramCommands.Cut"></Button>
//Initialize the SfDiagram 
SfDiagram diagramcontrol = new SfDiagram();

IGraphInfo graphinfo = diagramcontrol.Info as IGraphInfo;

//Cuts the selected elements from the diagram to the diagram’s clipboard
graphinfo.Commands.Cut.Execute(null);

Copy command

The Copy command is used to copy the selected diagram objects to the clipboard. Copy command can be executed using the keyboard shortcut CTRL + C.

NOTE

The Copy command is applicable only when one or more diagram elements are selected. If no elements are selected, the command will not perform any operation.

<Button Height="50" Content="Copy" Name="Copy" Command="Syncfusion:DiagramCommands.Copy"></Button>
//Initialize the SfDiagram 
SfDiagram diagramcontrol = new SfDiagram();

IGraphInfo graphinfo = diagramcontrol.Info as IGraphInfo;

//Copies the selected elements from the diagram to the diagram’s clipboard.
graphinfo.Commands.Copy.Execute(null);

Paste command

The Paste command is used to paste the clipboard content to the diagram page. Paste command can be executed using the keyboard shortcut CTRL + V.

NOTE

The Paste command is applicable only when the clipboard contains supported diagram content. If the clipboard is empty or contains unsupported content, the command will not perform any operation.

<Button Height="50" Content="Paste" Name="Paste" Command="Syncfusion:DiagramCommands.Paste"></Button>
//Initialize the SfDiagram 
SfDiagram diagramcontrol = new SfDiagram();

IGraphInfo graphinfo = diagramcontrol.Info as IGraphInfo;

//Pastes the diagram’s clipboard data (nodes or connectors) into the Diagram.
graphinfo.Commands.Paste.Execute(null);

Duplicate command

The Duplicate command is used to copy the selected diagram objects to the clipboard and paste the clipboard content to the diagram page. Duplicate command can be executed using the keyboard shortcut CTRL + D.

NOTE

When the Duplicate command is executed, a copy of the selected diagram elements is created and placed with a slight offset from the original elements to make the duplicated elements immediately visible.

NOTE

The Duplicate command creates copies of the selected diagram elements within the diagram. This operation does not modify or replace the existing contents of the clipboard.

<Button Height="50" Content="Duplicate" Name="Duplicate" Command="Syncfusion:DiagramCommands.Duplicate"></Button>
//Initialize the SfDiagram 
SfDiagram diagramcontrol = new SfDiagram();

IGraphInfo graphinfo = diagramcontrol.Info as IGraphInfo;

//Copy the diagram objects and Paste the clipboard's data (nodes or connectors) into the Diagram.
graphinfo.Commands.Duplicate.Execute(null);

Clipboard gif

View sample in GitHub

See Also

How to Display Different QuickCommands Based on Nodes in WPF Diagram?

How to disable or override clipboard support