title: How to change HirerachicalDataTemplate associated with the WPF TreeView programatically at run time?
body: <p>I have a TreeView control on my WPF window. I am giving only relevant XAML from my window.</p>
  
  <pre><code>&lt;Window.Resources&gt;
          &lt;HierarchicalDataTemplate x:Key="HierarchicalTemplate" ItemsSource="{Binding SubOrgUnitItems}"&gt;
              &lt;StackPanel Orientation="Horizontal"&gt;
                  &lt;Image Height="16" Source="{Binding ImagePath}" Stretch="Fill" Width="16"/&gt;
                  &lt;TextBlock Text="{Binding OrgUnitName}" Name="treeText" /&gt;
              &lt;/StackPanel&gt;
          &lt;/HierarchicalDataTemplate&gt;
      &lt;/Window.Resources&gt;
  
  
  
  &lt;TreeView Margin="10,35,10,10" BorderThickness="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" ScrollViewer.VerticalScrollBarVisibility="Auto"
                        IsTabStop="True" Name="orgTreeView" ItemsSource="{Binding}"  ItemTemplate="{DynamicResource HierarchicalTemplate}" TabIndex="700" SelectedItemChanged="orgTreeView_SelectedItemChanged" /&gt;
  </code></pre>
  
  <p>When the Collection of Organisations is bound to <code>DataContext</code> of the <code>TreeView</code>, items are displayed with the <code>OrgUnitName</code>'s value as a text at every node. 
  Now at  run time I want to see some other property's value as a text at every node. e.g. <code>OrgUnitCode</code> instead of <code>OrgUnitName</code>. Both are properties declared in the view model class associated with the treeview.</p>
  
  <p>How can i do it programatically at run time?</p>