Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The code you posted is not hierarchical, In other words: The MyPOCO Class is not containing a property <code>MyCollection&lt;MYPOCO&gt;</code> Children. Here is an example for the HierarchicalDataTemplate</p> <p>Xaml:</p> <pre><code>&lt;sdk:TreeView x:Name="MyTreeView" HorizontalAlignment="Left" ItemsSource="{Binding MyCollection}" Width="200" Height="280"&gt; &lt;sdk:TreeView.ItemTemplate&gt; &lt;sdk:HierarchicalDataTemplate ItemsSource="{Binding Path=Children}"&gt; &lt;TextBlock Text="{Binding Path=Header}"/&gt; &lt;sdk:HierarchicalDataTemplate.ItemTemplate&gt; &lt;sdk:HierarchicalDataTemplate ItemsSource="{Binding Path=Children}"&gt; &lt;TextBlock Text="{Binding Path=Header}"/&gt; &lt;/sdk:HierarchicalDataTemplate&gt; &lt;/sdk:HierarchicalDataTemplate.ItemTemplate&gt; &lt;/sdk:HierarchicalDataTemplate&gt; &lt;/sdk:TreeView.ItemTemplate&gt; &lt;/sdk:TreeView&gt; </code></pre> <p>Codebehind classes:</p> <pre><code>public class MyPoco { public MyPoco(string header, int sampleChildrenCount) { this.Header = header; this.Children = new ObservableCollection&lt;MyPoco&gt;(); if (sampleChildrenCount &gt; 0) { for (int i = 0; i &lt; sampleChildrenCount; i++) { string newHeader = String.Format("Test {0}", sampleChildrenCount * i); var myPoco = new MyPoco(newHeader, sampleChildrenCount - 1) this.Children.Add(myPoco); } } } public string Header { get; set; } public ObservableCollection&lt;MyPoco&gt; Children { get; set; } } public class MyViewModel { public MyViewModel() { MyCollection = new ObservableCollection&lt;MyPoco&gt;(); for (int i = 0; i &lt; 6; i++) { this.MyCollection.Add(new MyPoco(String.Format("Test {0}", i), 5)); } } public ObservableCollection&lt;MyPoco&gt; MyCollection { get; set; } } </code></pre> <p>Codebehind startup:</p> <pre><code>public MainPage() { public MainPage() { InitializeComponent(); MyTreeView.DataContext = new MyViewModel(); } } </code></pre>
 

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