Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A <code>HierarchicalDataTemplate</code> is a way of saying 'this is how you render this type of object and here is a property that can be probed to find the child nodes under this object'</p> <p>Therefore you need a single property that returns the 'children' of this node. e.g. (If you can't make both Group and Entry derive from a common Node type)</p> <pre><code>public class Group{ .... public IList&lt;object&gt; Items { get { IList&lt;object&gt; childNodes = new List&lt;object&gt;(); foreach (var group in this.SubGroups) childNodes.Add(group); foreach (var entry in this.Entries) childNodes.Add(entry); return childNodes; } } </code></pre> <p>Next you don't need a <code>HierDataTemplate</code> for entry since an entry doesn't have children. So the XAML needs to be changed to use the new Items property and a <code>DataTemplate</code> for Entry:</p> <pre><code>&lt;TreeView Name="GroupView" Grid.Row="0" Grid.Column="0" ItemsSource="{Binding}"&gt; &lt;TreeView.Resources&gt; &lt;HierarchicalDataTemplate DataType="{x:Type local:Group}" ItemsSource="{Binding Items}"&gt; &lt;TextBlock Text="{Binding Path=Name}" /&gt; &lt;/HierarchicalDataTemplate&gt; &lt;DataTemplate DataType="{x:Type local:Entry}" &gt; &lt;TextBlock Text="{Binding Path=Name}" /&gt; &lt;/DataTemplate&gt; &lt;/TreeView.Resources&gt; &lt;/TreeView&gt; </code></pre> <p>And here's what that looks like. <img src="https://lh4.ggpht.com/_nxgDpneh8yk/Syh6K2zgFxI/AAAAAAAAAzQ/QIRgTsKqhlk/s288/HierarchicalDataTemplate_longDay.jpg" alt="Screenshot of Output"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload