title: C# WPF - TreeView binding with Dictionary
body: <p>I need to fill out a TreeView with a list of dictionaries that I have.</p>
  
  <pre><code>List&lt;Dictionary&lt;string,object&gt;&gt; 
  </code></pre>
  
  <p>Where the Dictionaries have title and children keys </p>
  
  <pre><code>[{"title":"foo", "children":[]},]
  </code></pre>
  
  <p>However I am unable to figure out the binding. This is completely wrong. I need obviously to display dict["title"] and use dict["children"] as the children. </p>
  
  <pre><code>&lt;TreeView.ItemTemplate&gt;
      &lt;HierarchicalDataTemplate ItemsSource="{Binding Value}"&gt;
         &lt;HierarchicalDataTemplate.ItemTemplate&gt;
              &lt;DataTemplate&gt;
                  &lt;TextBlock Text="{Binding}"/&gt;
              &lt;/DataTemplate&gt;
          &lt;/HierarchicalDataTemplate.ItemTemplate&gt;
          &lt;TextBlock Text="{Binding Key}"/&gt;
      &lt;/HierarchicalDataTemplate&gt;
  &lt;/TreeView.ItemTemplate&gt;
  </code></pre>
  
  <p>Hah so apparently Binding supports [] syntax so this sort of works:</p>
  
  <pre><code>        &lt;TreeView.ItemTemplate&gt;
              &lt;HierarchicalDataTemplate ItemsSource="{Binding Path=[children]}"&gt;
                  &lt;HierarchicalDataTemplate.ItemTemplate&gt;
                      &lt;DataTemplate&gt;
                          &lt;TextBlock Text="{Binding Path=[title]}"/&gt;
                      &lt;/DataTemplate&gt;
                  &lt;/HierarchicalDataTemplate.ItemTemplate&gt;
                  &lt;TextBlock Text="{Binding Path=[title]}"/&gt;
              &lt;/HierarchicalDataTemplate&gt;
          &lt;/TreeView.ItemTemplate&gt;
  </code></pre>
  
  <p>Each dictionary can have children nested to however many levels they want however. Is this possible to handle? With the above template and the following code the grand child is not displayed.</p>
  
  <pre><code>        string s = @"[{""title"":""Title1"",""children"":[{""title"":""Child1"",""children"":[{""title"":""grandchild1"",""children"":[]}]}]}]";
  
          List&lt;Dictionary&lt;string, object&gt;&gt; marr = JsonConvert.DeserializeObject&lt;List&lt;Dictionary&lt;string, object&gt;&gt;&gt;(s);
          mTreeView.ItemsSource = marr;
  </code></pre>
  
  <p>By the way using [] in the Binding is called indexers and I found out about it from the docs at this link:</p>
  
  <p><a href="http://msdn.microsoft.com/en-us/library/ms752300.aspx#Path_Syntax" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms752300.aspx#Path_Syntax</a></p>