title: Not able to change the wpf default node linking line for treeview control
body: <p>I am trying to change the default node linking line for wpf  treeview  HierarchicalDataTemplate with help of converter.But still I am not able change the default look of tree view node linking .I tried to achieve this with help of below resource code but it is not changing the node default  look even though it does not throw any error . Please help me to change the default look of node linking .I want to show the node linking with line </p>
  
  <pre><code>&lt;UserControl x:Class="DevLake.OrgChart.UI.View.TreeView"
               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:local="clr-namespace:DevLake.OrgChart.UI.View"
               xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"&gt;
  
      &lt;UserControl.Resources&gt;
          &lt;local:TreeViewLineConverter x:Key="LineConverter"/&gt;
  
          &lt;SolidColorBrush x:Key="GlyphBrush" Color="#444" /&gt;
  
          &lt;!--=================================================================
        TreeViewItem
    ==================================================================--&gt;
          &lt;Style x:Key="ExpandCollapseToggleStyle" TargetType="ToggleButton"&gt;
              &lt;Setter Property="Focusable" Value="False"/&gt;
              &lt;Setter Property="Template"&gt;
                  &lt;Setter.Value&gt;
                      &lt;ControlTemplate TargetType="ToggleButton"&gt;
                          &lt;Grid
                Width="15"
                Height="13"
                Background="White"&gt;
                              &lt;Path x:Name="ExpandPath"
                  HorizontalAlignment="Left"
                  VerticalAlignment="Center"
                  Margin="1,1,1,1"
                  Fill="{StaticResource GlyphBrush}"
                  Data="M 4 0 L 8 4 L 4 8 Z"/&gt;
                          &lt;/Grid&gt;
                          &lt;ControlTemplate.Triggers&gt;
                              &lt;Trigger Property="IsChecked"
                     Value="True"&gt;
                                  &lt;Setter Property="Data"
                      TargetName="ExpandPath"
                      Value="M 0 4 L 8 4 L 4 8 Z"/&gt;
                              &lt;/Trigger&gt;
                          &lt;/ControlTemplate.Triggers&gt;
                      &lt;/ControlTemplate&gt;
                  &lt;/Setter.Value&gt;
              &lt;/Setter&gt;
          &lt;/Style&gt;
          &lt;Style x:Key="TreeViewItemFocusVisual"&gt;
              &lt;Setter Property="Control.Template"&gt;
                  &lt;Setter.Value&gt;
                      &lt;ControlTemplate&gt;
                          &lt;Border&gt;
                              &lt;Rectangle Margin="0,0,0,0"
                       StrokeThickness="5"
                       Stroke="Black"
                       StrokeDashArray="1 2"
                       Opacity="0"/&gt;
                          &lt;/Border&gt;
                      &lt;/ControlTemplate&gt;
                  &lt;/Setter.Value&gt;
              &lt;/Setter&gt;
          &lt;/Style&gt;
          &lt;Style x:Key="{x:Type TreeViewItem}"
           TargetType="{x:Type TreeViewItem}"&gt;
              &lt;Setter Property="Background"
            Value="Transparent"/&gt;
              &lt;Setter Property="HorizontalContentAlignment"
            Value="{Binding Path=HorizontalContentAlignment,
                RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/&gt;
              &lt;Setter Property="VerticalContentAlignment"
            Value="{Binding Path=VerticalContentAlignment,
                RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/&gt;
              &lt;Setter Property="Padding"
            Value="1,0,0,0"/&gt;
              &lt;Setter Property="Foreground"
            Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/&gt;
              &lt;Setter Property="FocusVisualStyle"
            Value="{StaticResource TreeViewItemFocusVisual}"/&gt;
              &lt;Setter Property="Template"&gt;
                  &lt;Setter.Value&gt;
                      &lt;ControlTemplate TargetType="{x:Type TreeViewItem}"&gt;
                          &lt;Grid&gt;
                              &lt;Grid.ColumnDefinitions&gt;
                                  &lt;ColumnDefinition MinWidth="19"
                            Width="Auto"/&gt;
                                  &lt;ColumnDefinition Width="Auto"/&gt;
                                  &lt;ColumnDefinition Width="*"/&gt;
                              &lt;/Grid.ColumnDefinitions&gt;
                              &lt;Grid.RowDefinitions&gt;
                                  &lt;RowDefinition Height="Auto"/&gt;
                                  &lt;RowDefinition/&gt;
                              &lt;/Grid.RowDefinitions&gt;
  
                              &lt;!-- Connecting Lines --&gt;
                              &lt;Rectangle x:Name="HorLn" Height="1" Stroke="#8888"  Margin="10,0,0,0" SnapsToDevicePixels="true"/&gt;
                              &lt;Rectangle x:Name="VerLn" Width="1" Stroke="#8888" Grid.RowSpan="2" SnapsToDevicePixels="true"/&gt;
                              &lt;ToggleButton x:Name="Expander"
                        Style="{StaticResource ExpandCollapseToggleStyle}"
                        IsChecked="{Binding Path=IsExpanded,
                                RelativeSource={RelativeSource TemplatedParent}}"
                        ClickMode="Press"/&gt;
                              &lt;Border Name="Bd"
                    Grid.Column="1"
                    Background="{TemplateBinding Background}"
                    BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}"
                    Padding="{TemplateBinding Padding}"&gt;
                                  &lt;ContentPresenter x:Name="PART_Header"
                            ContentSource="Header"
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"/&gt;
                              &lt;/Border&gt;
                              &lt;ItemsPresenter x:Name="ItemsHost"
                        Grid.Row="1"
                        Grid.Column="1"
                        Grid.ColumnSpan="2"/&gt;
                          &lt;/Grid&gt;
                          &lt;ControlTemplate.Triggers&gt;
  
                              &lt;!-- This trigger changes the connecting lines if the item is the last in the list --&gt;
                              &lt;DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource LineConverter}}" Value="true"&gt;
                                  &lt;Setter TargetName="VerLn"
                      Property="Height"
                      Value="6"/&gt;
                                  &lt;Setter TargetName="VerLn"
                      Property="VerticalAlignment"
                      Value="Top"/&gt;
                              &lt;/DataTrigger&gt;
                              &lt;Trigger Property="IsExpanded"
                     Value="false"&gt;
                                  &lt;Setter TargetName="ItemsHost"
                      Property="Visibility"
                      Value="Collapsed"/&gt;
                              &lt;/Trigger&gt;
                              &lt;Trigger Property="HasItems"
                     Value="false"&gt;
                                  &lt;Setter TargetName="Expander"
                      Property="Visibility"
                      Value="Hidden"/&gt;
                              &lt;/Trigger&gt;
                              &lt;MultiTrigger&gt;
                                  &lt;MultiTrigger.Conditions&gt;
                                      &lt;Condition Property="HasHeader"
                           Value="false"/&gt;
                                      &lt;Condition Property="Width"
                           Value="Auto"/&gt;
                                  &lt;/MultiTrigger.Conditions&gt;
                                  &lt;Setter TargetName="PART_Header"
                      Property="MinWidth"
                      Value="75"/&gt;
                              &lt;/MultiTrigger&gt;
                              &lt;MultiTrigger&gt;
                                  &lt;MultiTrigger.Conditions&gt;
                                      &lt;Condition Property="HasHeader"
                           Value="false"/&gt;
                                      &lt;Condition Property="Height"
                           Value="Auto"/&gt;
                                  &lt;/MultiTrigger.Conditions&gt;
                                  &lt;Setter TargetName="PART_Header"
                      Property="MinHeight"
                      Value="19"/&gt;
                              &lt;/MultiTrigger&gt;
                              &lt;Trigger Property="IsSelected"
                     Value="true"&gt;
                                  &lt;Setter TargetName="Bd"
                      Property="Background"
                      Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/&gt;
                                  &lt;Setter Property="Foreground"
                      Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/&gt;
                              &lt;/Trigger&gt;
                              &lt;MultiTrigger&gt;
                                  &lt;MultiTrigger.Conditions&gt;
                                      &lt;Condition Property="IsSelected"
                           Value="true"/&gt;
                                      &lt;Condition Property="IsSelectionActive"
                           Value="false"/&gt;
                                  &lt;/MultiTrigger.Conditions&gt;
                                  &lt;Setter TargetName="Bd"
                      Property="Background"
                      Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/&gt;
                                  &lt;Setter Property="Foreground"
                      Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/&gt;
                              &lt;/MultiTrigger&gt;
                              &lt;Trigger Property="IsEnabled"
                     Value="false"&gt;
                                  &lt;Setter Property="Foreground"
                      Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/&gt;
                              &lt;/Trigger&gt;
                          &lt;/ControlTemplate.Triggers&gt;
                      &lt;/ControlTemplate&gt;
                  &lt;/Setter.Value&gt;
              &lt;/Setter&gt;
          &lt;/Style&gt;
  
      &lt;/UserControl.Resources&gt;
  
      &lt;StackPanel&gt;
          &lt;TreeView x:Name="tvMain" ItemsSource="{Binding Root}" BorderThickness="0"&gt;
              &lt;TreeView.ItemTemplate&gt;
                  &lt;HierarchicalDataTemplate ItemsSource="{Binding Children}"&gt;
                      &lt;StackPanel Orientation="Horizontal"&gt;
                          &lt;Image Source="{Binding ImagePath}" MaxHeight="40" MaxWidth="40" Margin="2"/&gt;
                          &lt;TextBlock VerticalAlignment="Center"&gt;            
                          &lt;TextBlock.Text&gt;
                              &lt;MultiBinding StringFormat=" {0} {1}"&gt;
                                  &lt;Binding Path="FirstName"/&gt;
                                  &lt;Binding Path="LastName"/&gt;
                              &lt;/MultiBinding&gt;
  
  
                          &lt;/TextBlock.Text&gt;
                          &lt;/TextBlock&gt;
                          &lt;StackPanel.Style&gt;
                              &lt;Style&gt;
                                  &lt;Style.Triggers&gt;
                                      &lt;DataTrigger Binding="{Binding IsSelected}" Value="true"&gt;
                                          &lt;Setter Property="StackPanel.Background" Value="LightBlue"/&gt;
                                      &lt;/DataTrigger&gt;
                                  &lt;/Style.Triggers&gt;
                              &lt;/Style&gt;
                          &lt;/StackPanel.Style&gt;
                      &lt;/StackPanel&gt;
                  &lt;/HierarchicalDataTemplate&gt;
              &lt;/TreeView.ItemTemplate&gt;
              &lt;TreeView.ItemContainerStyle&gt;
                  &lt;Style TargetType="{x:Type TreeViewItem}"&gt;
                      &lt;Setter Property="IsExpanded" Value="True"/&gt;
                      &lt;Setter Property="IsSelected" Value="{Binding IsSelected}"/&gt;
                  &lt;/Style&gt;
              &lt;/TreeView.ItemContainerStyle&gt;
              &lt;i:Interaction.Triggers&gt;
                  &lt;i:EventTrigger EventName="SelectedItemChanged"&gt;
                      &lt;i:InvokeCommandAction Command="{Binding SelectedCommand}" 
                                             CommandParameter="{Binding ElementName=tvMain, Path=SelectedItem}"/&gt;
                  &lt;/i:EventTrigger&gt;
              &lt;/i:Interaction.Triggers&gt;
          &lt;/TreeView&gt;
      &lt;/StackPanel&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>and my converter code is :</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Windows;
  using System.Windows.Controls;
  using System.Windows.Data;
  using System.Windows.Documents;
  using System.Windows.Input;
  using System.Windows.Media;
  using System.Windows.Media.Imaging;
  using System.Windows.Navigation;
  using System.Windows.Shapes;
  
  namespace DevLake.OrgChart.UI.View
  {
      /// &lt;summary&gt;
      /// Interaction logic for TreeView.xaml
      /// &lt;/summary&gt;
      public partial class TreeView : UserControl
      {
          public TreeView()
          {
              InitializeComponent();
          }
      }
  
      class TreeViewLineConverter : IValueConverter
      {
          public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
          {
              TreeViewItem item = (TreeViewItem)value;
              ItemsControl ic = ItemsControl.ItemsControlFromItemContainer(item);
              return ic.ItemContainerGenerator.IndexFromContainer(item) == ic.Items.Count - 1;
          }
  
          public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
          {
              throw new Exception("The method or operation is not implemented.");
          }
      }
  }
  </code></pre>