alexa
menu

WPF

  • Code Examples
  • Upgrade Guide
  • User Guide
  • Demos
  • Support
  • Forums
  • Download

    Show / Hide Table of Contents

    Class ForceDirectedTreeLayout

    Represents a class to arrange the nodes and connectors automatically in a Force directed tree layout.

    Inheritance
    System.Object
    LayoutBase
    TreeLayoutBase
    ForceDirectedTreeLayout
    Implements
    ILayout
    System.ComponentModel.INotifyPropertyChanged
    Inherited Members
    LayoutBase.Bounds
    LayoutBase.HorizontalAlignment
    LayoutBase.Margin
    LayoutBase.VerticalAlignment
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.ToString()
    TreeLayoutBase.HorizontalSpacing
    TreeLayoutBase.OnPropertyChanged(String)
    TreeLayoutBase.PropertyChanged
    TreeLayoutBase.SpaceBetweenSubTrees
    TreeLayoutBase.VerticalSpacing
    Namespace: Syncfusion.UI.Xaml.Diagram.Layout
    Assembly: Syncfusion.SfDiagram.WPF.dll
    Syntax
    public class ForceDirectedTreeLayout : TreeLayoutBase, ILayout, IInternalLayout, INotifyPropertyChanged
    Examples

    Below example shows how to create Force Directed Tree Layout

    • Model.cs
    public class ForceDirectedDetails
    {
      public string Id { get; set; }
    public string Role { get; set; }
    public string Manager { get; set; }
    }
    public class ForceDirectedDataItems : List<ForceDirectedDetails>
    {
    }
    
    <code ><![CDATA[
     <local:ForceDirectedDataItems x:Key="ForceDirectedSource">
       <local:ForceDirectedDetails Id = "Dev" Role="Team" />
       <local:ForceDirectedDetails Id = "Dept" Role="PO-5" Manager="Dev" />
       <local:ForceDirectedDetails Id = "PO1" Role="PO-1" Manager="Dev" />
       <local:ForceDirectedDetails Id = "PO2" Role="PO-2" Manager="Dev"/>
      <local:ForceDirectedDetails Id = "PO3" Role="PO-3" Manager="Dev" />
       <local:ForceDirectedDetails Id = "PO4" Role="PO-4" Manager="Dev" />
       <local:ForceDirectedDetails Id = "PO1_T1" Role="Team-1" Manager="PO1" />
       <local:ForceDirectedDetails Id = "PO1_T2" Role="Team-2" Manager="PO1" />
       <local:ForceDirectedDetails Id = "PO1_T3" Role="Team-3" Manager="PO1" />
       <local:ForceDirectedDetails Id = "PO1_T4" Role="Team-4" Manager="PO1"/>
       <local:ForceDirectedDetails Id = "PO2_T1" Role="Team-1" Manager="PO2" />
       <local:ForceDirectedDetails Id = "PO2_T2" Role="Team-2" Manager="PO2" />
       <local:ForceDirectedDetails Id = "PO2_T3" Role="Team-3" Manager="PO2" />
       <local:ForceDirectedDetails Id = "PO2_T4" Role="Team-4" Manager="PO2" />
       <local:ForceDirectedDetails Id = "PO3_T1" Role="Team-1" Manager="PO3"/>
       <local:ForceDirectedDetails Id = "PO3_T2" Role="Team-2" Manager="PO3" />
       <local:ForceDirectedDetails Id = "PO3_T3" Role="Team-3" Manager="PO3"/>
       <local:ForceDirectedDetails Id = "PO3_T4" Role="Team-4" Manager="PO3" />
       <local:ForceDirectedDetails Id = "PO4_T1" Role="Team-1" Manager="PO4" />
       <local:ForceDirectedDetails Id = "PO4_T2" Role="Team-2" Manager="PO4" />
       <local:ForceDirectedDetails Id = "PO4_T3" Role="Team-3" Manager="PO4" />
       <local:ForceDirectedDetails Id = "PO4_T4" Role="Team-4" Manager="PO4" />
       <local:ForceDirectedDetails Id = "Sales" Role="Sales Team" Manager="Dept" />
       <local:ForceDirectedDetails Id = "AGM1" Role="AGM-1" Manager="Sales" />
       <local:ForceDirectedDetails Id = "AGM2" Role="AGM-2" Manager="Sales"/>
    </local:ForceDirectedDataItems>
    
    <!--Initializes the DataSourceSettings -->
    <Syncfusion:DataSourceSettings x:Key="DataSources"  DataSource="{StaticResource ForceDirectedSource}"
                    ParentId="Manager" Id="Id"/>
    
    <Syncfusion:ForceDirectedTree x:Key="layout" x:Name="DirectedTreeLayout"  ConnectorLength = "150"
                                   AttractionStrength = "0.7"
                                   RepulsionStrength = "25000"
                                  MaximumIteration = "500" />
    
    <Syncfusion:LayoutManager x:Key="Layoutmanager"  Layout="{StaticResource layout}"/>   
    
    <!--Initializes the SfDiagram-->
    <Syncfusion:SfDiagram x:Name="Diagram" 
                          DataSourceSettings="{StaticResource DataSources}"
                                 LayoutManager="{Binding Layoutmanager}"/>

    Constructors

    ForceDirectedTreeLayout()

    Initializes the new instance of the ForceDirectedTreeLayout class.

    Declaration
    public ForceDirectedTreeLayout()

    Properties

    AttractionStrength

    Gets or sets the strength of the attractive force that pulls connected nodes toward each other.

    Declaration
    public double AttractionStrength { get; set; }
    Property Value
    Type Description
    System.Double

    A System.Double indicating the attraction strength. The default value is 0.5. Minimum value is 0 and Maximum value is 1.

    Remarks

    The attraction strength determines how strongly connected nodes are pulled toward each other.
    Higher values will result in tighter clustering of directly connected nodes, emphasizing their relationships.

    Examples

    This example demonstrates how to initialize AttractionStrength in force-directed tree layout . Below example shows how the AttractionStrength is assigned for ForceDirectedTree Layout.

    • ViewModel.cs
    • MainWindow.xaml
     
    diagram.LayoutManager = new LayoutManager()
    {
    Layout = new ForceDirectedTreeLayout()
    {
      AttractionStrength = 0.7,
    },
    };

    This example shows how the AttractionStrength is assigned for ForceDirectedTree Layout.

    <Syncfusion:DataSourceSettings x:Key="DataSources"  DataSource="{StaticResource ForceDirectedSource}"
                    ParentId="Manager" Id="Id"/>
    <Syncfusion:ForceDirectedTreeLayout x:Key="layout" x:Name="DirectedTreeLayout"  ConnectorLength = "150"
                                   AttractionStrength = "0.7"
                                   RepulsionStrength = "25000"
                                  MaximumIteration = "500" />
    <Syncfusion:LayoutManager x:Key="Layoutmanager"  Layout="{StaticResource layout}"/>   
    <!--Initializes the SfDiagram-->
    <Syncfusion:SfDiagram x:Name="Diagram" 
                          DataSourceSettings="{StaticResource DataSources}"
                                 LayoutManager="{Binding Layoutmanager}"/>

    LayoutRoot

    Gets or sets the root node of the layout.

    Declaration
    public override object LayoutRoot { get; set; }
    Property Value
    Type
    System.Object
    Overrides
    TreeLayoutBase.LayoutRoot
    Remarks

    This property is part of the base layout infrastructure but is not used by the ForceDirectedTreeLayout implementation.

    MaximumIteration

    Gets or sets the maximum number of iterations the simulation will run before stopping.

    Declaration
    public int MaximumIteration { get; set; }
    Property Value
    Type Description
    System.Int32

    An System.Int32 representing the total number of iterations. The default value is 300. Minimum value is 100.

    Remarks

    The force-directed layout is an iterative process. A higher number of iterations can lead to a more stable and aesthetically pleasing layout but will increase the computation time. A lower value provides faster rendering at the cost of potential layout quality.

    Examples

    This example demonstrates how to initialize MaximumIteration in force-directed tree layout . Below example shows how the AttractionStrength is assigned for ForceDirectedTree Layout.

    • ViewModel.cs
    • MainWindow.xaml
     
    diagram.LayoutManager = new LayoutManager()
    {
    Layout = new ForceDirectedTreeLayout()
    {
      MaximumIteration = 500,
    },
    };

    This example shows how the AttractionStrength is assigned for ForceDirectedTree Layout.

    <Syncfusion:DataSourceSettings x:Key="DataSources"  DataSource="{StaticResource ForceDirectedSource}"
                    ParentId="Manager" Id="Id"/>
    <Syncfusion:ForceDirectedTreeLayout x:Key="layout" x:Name="DirectedTreeLayout"  ConnectorLength = "150"
                                   AttractionStrength = "0.7"
                                   RepulsionStrength = "25000"
                                  MaximumIteration = "500" />
    <Syncfusion:LayoutManager x:Key="Layoutmanager"  Layout="{StaticResource layout}"/>   
    <!--Initializes the SfDiagram-->
    <Syncfusion:SfDiagram x:Name="Diagram" 
                          DataSourceSettings="{StaticResource DataSources}"
                                 LayoutManager="{Binding Layoutmanager}"/>

    RepulsionStrength

    Gets or sets the strength of the repulsive force that pushes all nodes away from each other.

    Declaration
    public int RepulsionStrength { get; set; }
    Property Value
    Type Description
    System.Int32

    An System.Int32 indicating the strength of the repulsion. The default value is 5000. Minimum value is 3000.

    Remarks

    This is the primary force responsible for preventing nodes from overlapping. Increasing this value will create more white space around all nodes, globally pushing them apart.

    Examples

    This example demonstrates how to initialize RepulsionStrength in force-directed tree layout. Below example shows how the AttractionStrength is assigned for ForceDirectedTree Layout.

    • ViewModel.cs
    • MainWindow.xaml
     
    diagram.LayoutManager = new LayoutManager()
    {
    Layout = new ForceDirectedTreeLayout()
    {
      RepulsionStrength = 25000,
    },
    };

    This example shows how the AttractionStrength is assigned for ForceDirectedTree Layout.

    <Syncfusion:DataSourceSettings x:Key="DataSources"  DataSource="{StaticResource ForceDirectedSource}"
                    ParentId="Manager" Id="Id"/>
    <Syncfusion:ForceDirectedTreeLayout x:Key="layout" x:Name="DirectedTreeLayout"  ConnectorLength = "150"
                                   AttractionStrength = "0.7"
                                   RepulsionStrength = "25000"
                                  MaximumIteration = "500" />
    <Syncfusion:LayoutManager x:Key="Layoutmanager"  Layout="{StaticResource layout}"/>   
    <!--Initializes the SfDiagram-->
    <Syncfusion:SfDiagram x:Name="Diagram" 
                          DataSourceSettings="{StaticResource DataSources}"
                                 LayoutManager="{Binding Layoutmanager}"/>

    Methods

    InvalidateLayout()

    Invalidates the arrange state (layout) for the element.

    Declaration
    public override void InvalidateLayout()
    Overrides
    LayoutBase.InvalidateLayout()

    UpdateLayout()

    Method to update the currently arranged Nodes and Connectors.

    Declaration
    public override void UpdateLayout()
    Overrides
    LayoutBase.UpdateLayout()

    UpdateLayout(Object)

    Updates the currently arranged nodes and connectors.

    Declaration
    public override void UpdateLayout(object fixedNode)
    Parameters
    Type Name Description
    System.Object fixedNode

    The node used as an anchor for the layout.

    Overrides
    LayoutBase.UpdateLayout(Object)
    Remarks

    This method is inherited from the base layout. The ForceDirectedTreeLayout algorithm does not use this method because its layout is dynamically recalculated using force simulation.

    Implements

    ILayout
    System.ComponentModel.INotifyPropertyChanged
    Back to top Generated by DocFX
    Copyright © 2001 - 2026 Syncfusion Inc. All Rights Reserved