title: Using XAML resourceDictionary in code
body: <p>that's resourcedictionay file: TopologyTree.xaml</p>
  
  <pre><code>&lt;ResourceDictionary 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:local="clr-namespace:autoDraw.ViewModel.Topology"
  &gt;
  
  &lt;HierarchicalDataTemplate x:Key="TopologyTreeBase" DataType="{x:Type local:Base}" ItemsSource="{Binding children}"&gt;
      &lt;StackPanel Orientation="Horizontal"&gt;
          &lt;CheckBox IsChecked="{Binding IsChecked}"&gt;&lt;/CheckBox&gt;
          &lt;TextBlock Text="{Binding name}"&gt;&lt;/TextBlock&gt;
      &lt;/StackPanel&gt;
  &lt;/HierarchicalDataTemplate&gt;
  
  &lt;/ResourceDictionary&gt;
  </code></pre>
  
  <p>Side C#</p>
  
  <pre><code>objectTree.Resources = new ResourceDictionary();
  objectTree.Resources.Source = new Uri("GUI/TopologyTree.xaml", UriKind.Relative);
  </code></pre>
  
  <p>while objectTree is a TreeView</p>
  
  <p>how ever that doesn't work.</p>
  
  <p>I have tried as followed which worked, but I need to redefine DataType here, so I think it's not so good.</p>
  
  <pre><code>var resourceDictionary = new ResourceDictionary();
  resourceDictionary.Source = new Uri("GUI/TopologyTree.xaml", UriKind.Relative);
  
  objectTree.Resources.Add(
      new DataTemplateKey(typeof(ViewModel.Topology.Base)),
      resourceDictionary["TopologyTreeBase"] as HierarchicalDataTemplate
  );
  </code></pre>
  
  <p>What's more, I have tried put the content of xaml into the xmal window directly as followed, That works, but I need it be loaded dyanmically, so it just proven that my xmal is good.</p>
  
  <pre><code>    &lt;TreeView Name="objectTree" Grid.Column="4" Margin="3" Grid.Row="1" Grid.RowSpan="3"&gt;
          &lt;TreeView.Resources&gt;
              &lt;HierarchicalDataTemplate DataType="{x:Type local:Topology.Base}" ItemsSource="{Binding children}"&gt;
                  &lt;StackPanel Orientation="Horizontal"&gt;
                      &lt;CheckBox IsChecked="{Binding IsChecked}"&gt;&lt;/CheckBox&gt;
                      &lt;TextBlock Text="{Binding name}"&gt;&lt;/TextBlock&gt;
                  &lt;/StackPanel&gt;
              &lt;/HierarchicalDataTemplate&gt;
          &lt;/TreeView.Resources&gt;
      &lt;/TreeView&gt;
  </code></pre>
  
  <p>Could anyone help me have a way to use it in C# side simply?</p>