Articles in this section
Category / Section

How to draw node in WPF Diagram (SfDiagram)?

1 min read

Nodes can be interactively drawn by clicking and dragging the WPF Diagram (SfDiagram) surface by using DrawingTool and GetDrawType Event. We have provided code example and screenshot to represent this.

C#

//Event to get the Drawing Type.
(diagramControl.Info as IGraphInfo).GetDrawType += MainPage_GetDrawType;
//to draw Node
diagramControl.DrawingTool = DrawingTool.Node;
//to draw the Nodes continuously.
diagramControl.Tool = Tool.ContinuesDraw;
 
void MainPage_GetDrawType(object sender, DrawTypeEventArgs args)
{
  args.DrawItem = new TextBlock()
  {
    Text = "Rectangle",
    HorizontalAlignment = HorizontalAlignment.Center,
    VerticalAlignment = VerticalAlignment.Center
  };
}

XAML

<Style TargetType="Path" x:Key="shapestyle">
    <Setter Property="Fill" Value="#fcbc7c"></Setter>
    <Setter Property="Stroke" Value="#f89b4c"/>
    <Setter Property="Stretch" Value="Fill"></Setter>
</Style>
<Style TargetType="{x:Type syncfusion:Node}">
    <Setter Property="Shape">
         <Setter.Value>
              <RectangleGeometry Rect="10,10,10,10"/>
         </Setter.Value>
    </Setter>
    <Setter Property="ShapeStyle" Value="{StaticResource shapestyle}"></Setter>
</Style>

 

WPF Diagram with Node

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied