SelectTool Command in WPF Diagram (SfDiagram)

29 Jan 20252 minutes to read

The SelectTool command of the diagram helps to change the DrawingTool and Tool properties to a specified value. The SelectToolCommandParameter of SelectTool command is used to represent a specific tool.

Property Description
Tool It is used to customize the tools of the diagram.
DrawingTool It is used to specify the drawing tool, which is valid only if the Tool is set as either ContinuesDraw or DrawOnce.
ConnectorType It is used to specify the type (such as Orthogonal, Straight and Cubic-Curve etc.) of the connector to be drawn.

For details , refer Tools and DrawingTools

<!-- To draw an ellipse node-->
 <Syncfusion:SelectToolCommandParameter DrawingTool="Ellipse" Tool="ContinuesDraw"  x:Key="SelectToolEllipseCommandParameter"/>
 
 <!-- To draw a straight line connector-->
 <Syncfusion:SelectToolCommandParameter DrawingTool="Connector" ConnectorType="Line" Tool="ContinuesDraw"  x:Key="SelectToolConnectorCommandParameter"/>
 
 <!-- To draw a text node-->
 <Syncfusion:SelectToolCommandParameter DrawingTool="TextNode" Tool="ContinuesDraw"  x:Key="SelectToolTextCommandParameter"/>
 
<Button Height="50" Content="ConnectorTool" Name="Connector" Command="Syncfusion:DiagramCommands.SelectTool" CommandParameter="{StaticResource SelectToolConnectorCommandParameter}"></Button>

<Button Height="50" Content="EllipseTool" Name="Ellipse" Command="Syncfusion:DiagramCommands.SelectTool" CommandParameter="{StaticResource SelectToolEllipseCommandParameter}"></Button>

<Button Height="50" Content="TextTool" Name="TextNode" Command="Syncfusion:DiagramCommands.SelectTool" CommandParameter="{StaticResource SelectToolTextCommandParameter}"></Button>
IGraphInfo graphinfo = diagramcontrol.Info as IGraphInfo;

// To draw a straight line connector            
graphinfo.Commands.SelectTool.Execute(new SelectToolCommandParameter() 
{ 
    Tool = Tool.ContinuesDraw, DrawingTool = DrawingTool.Connector, ConnectorType = ConnectorType.Line 
});

// To draw an ellipse node
graphinfo.Commands.SelectTool.Execute(new SelectToolCommandParameter() 
{ 
    Tool = Tool.ContinuesDraw, DrawingTool = DrawingTool.Ellipse
});

// To draw a text node
graphinfo.Commands.SelectTool.Execute(new SelectToolCommandParameter() 
{ 
    Tool = Tool.ContinuesDraw, DrawingTool = DrawingTool.TextNode 
});

Gif for SelectTool command

View sample in GitHub