# diagram-treeview-binding

> Diagram with TreeView binding, filtering, and synchronized selection between tree and diagram.

**Framework:** wpf  **Component:** Diagram  **Variant:** treeview-binding

## Get this item

**If you are an agent, fetch the JSON.** Source is inlined, so one request is enough and no tooling is required:

```
GET https://ai.syncfusion.com/r/wpf/diagram-treeview-binding.json
```

**Install Package(s)**

```bash
dotnet add package Syncfusion.SfDiagram.WPF
```

**Notes**

- Syncfusion release: 2026 Volume 3 (v35.1.37)
- The Syncfusion package is licensed. The composition in this file is source you own and edit. See https://ai.syncfusion.com/licensing.md

## Source files

### src/components/diagram-treeview-binding/Diagram.xaml

```xaml
<UserControl
    x:Class="TreeViewBinding.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
    xmlns:local="clr-namespace:TreeViewBinding"
    mc:Ignorable="d"
    d:DesignHeight="450" d:DesignWidth="800">

    <UserControl.DataContext>
        <local:TreeViewBindingDataSource />
    </UserControl.DataContext>

    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Syncfusion.SfDiagram.WPF;component/Resources/BasicShapes.xaml" />
            </ResourceDictionary.MergedDictionaries>

            <Style TargetType="syncfusion:Connector">
                <Setter Property="ConnectorGeometryStyle">
                    <Setter.Value>
                        <Style TargetType="Path">
                            <Setter Property="Stroke" Value="CornflowerBlue" />
                            <Setter Property="StrokeThickness" Value="1" />
                        </Style>
                    </Setter.Value>
                </Setter>
                <Setter Property="TargetDecoratorStyle">
                    <Setter.Value>
                        <Style TargetType="Path">
                            <Setter Property="Fill" Value="CornflowerBlue" />
                            <Setter Property="StrokeThickness" Value="1" />
                        </Style>
                    </Setter.Value>
                </Setter>
            </Style>

            <Style TargetType="syncfusion:Node">
                <Setter Property="UnitWidth" Value="135" />
                <Setter Property="UnitHeight" Value="40" />
                <Setter Property="Width" Value="135" />
                <Setter Property="Height" Value="40" />
                <Setter Property="ShapeStyle">
                    <Setter.Value>
                        <Style TargetType="Path">
                            <Setter Property="Fill" Value="CornflowerBlue" />
                            <Setter Property="Stretch" Value="Fill" />
                            <Setter Property="Stroke" Value="WhiteSmoke" />
                            <Setter Property="StrokeThickness" Value="2" />
                        </Style>
                    </Setter.Value>
                </Setter>
                <Setter Property="ContentTemplate">
                    <Setter.Value>
                        <DataTemplate>
                            <Border Width="135" Height="40" VerticalAlignment="Center"
                                    HorizontalAlignment="Center" BorderBrush="Transparent">
                                <TextBlock Margin="5" TextWrapping="Wrap" FontSize="12"
                                           Foreground="White" Background="Transparent"
                                           Text="{Binding Name}"
                                           VerticalAlignment="Center" HorizontalAlignment="Center" />
                            </Border>
                        </DataTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
            <HierarchicalDataTemplate x:Key="treeTemplate" ItemsSource="{Binding SubItems}">
                <TextBlock Text="{Binding Name}" />
            </HierarchicalDataTemplate>

            <!-- Template that renders the name of a node inside the diagram. -->
            <DataTemplate x:Key="EmployeeCardTemplate">
                <Border Width="135" Height="40" VerticalAlignment="Center"
                        HorizontalAlignment="Center" BorderBrush="Transparent">
                    <TextBlock Margin="5" TextWrapping="Wrap" FontSize="12" Foreground="White"
                               Background="Transparent" Text="{Binding Name}"
                               VerticalAlignment="Center" HorizontalAlignment="Center" />
                </Border>
            </DataTemplate>
        </ResourceDictionary>
    </UserControl.Resources>

    <Grid x:Name="GridRoot">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="250" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="50" />
            <RowDefinition Height="9.3*" />
        </Grid.RowDefinitions>

        <!-- Property area with the add and delete commands. -->
        <Grid Grid.ColumnSpan="2" x:Name="PropertyRowPanel">
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center">
                <Button Margin="10,0,0,0" Content="Add Node" Name="Add" Width="100" Height="30"
                        Command="{Binding AddNode}" IsEnabled="{Binding IsAddButtonEnabled}" />
                <Button Margin="10,0,0,0" Content="Delete Node" Name="Delete" Width="100" Height="30"
                        Command="{Binding DeleteNode}" IsEnabled="{Binding IsDeleteButtonEnabled}" />
            </StackPanel>
            <TextBlock FontWeight="Normal" FontSize="14" Text="SfDiagram Binding With TreeView"
                       HorizontalAlignment="Right" VerticalAlignment="Center" />
        </Grid>

        <!-- The tree view and the diagram share a single items source. -->
        <syncfusion:SfTreeView HorizontalAlignment="Center"
                                Margin="5"
                                VerticalAlignment="Stretch"
                                Grid.Row="1" Name="SfTreeView"
                                ItemsSource="{Binding Datas}"
                                SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
                                ChildPropertyName="SubItems"
                                ItemTemplate="{StaticResource treeTemplate}"
                                ShowRootLines="False"
                                AutoExpandMode="AllNodes"
                                IsAnimationEnabled="True" />

        <syncfusion:SfDiagram Grid.Row="1" x:Name="Diagram" Grid.Column="1" Margin="5,6,5,8"
                              ItemAddedCommand="{Binding ItemAddedCommand}" ItemDeletingCommand="{Binding ItemDeletingCommand}" ItemSelectedCommand="{Binding ItemSelectedCommand}" ItemUnSelectedCommand="{Binding ItemUnSelectedCommand}" Tool="{Binding Tool}" Nodes="{Binding Nodes}" Connectors="{Binding Connectors}" DefaultConnectorType="{Binding DefaultConnectorType}" PageSettings="{Binding PageSettings}" SelectedItems="{Binding SelectedItems}" LayoutManager="{Binding LayoutManager}" DataSourceSettings="{Binding DataSourceSettings}" />
    </Grid>
</UserControl>

```
