Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is how I got it to work, thanks Matt!</p> <pre><code>public abstract class ObservableHierarchy&lt;T&gt; { public T Current { get; set; } public ObservableCollection&lt;ObservableHierarchy&lt;T&gt;&gt; Children { get; set; } public ObservableHierarchy( T current, Func&lt;T, IEnumerable&lt;T&gt;&gt; expand ) { this.Current = current; this.Children = new ObservableCollection&lt;ObservableHierarchy&lt;T&gt;&gt;(); foreach ( var item in expand( current ) ) { Children.Add( Create( item ) ); } } protected abstract ObservableHierarchy&lt;T&gt; Create( T item ); } </code></pre> <p>Then I specialize that base class to whatever data class I'm currently using.</p> <pre><code>public class ObservableFolderHierarchy: ObservableHierarchy&lt;FolderEntity&gt; { public ObservableFolderHierarchy( FolderEntity root ) : base( root, x =&gt; x.FolderEntities ) { } protected override ObservableHierarchy&lt;FolderEntity&gt; Create( FolderEntity item ) { return new ObservableFolderHierarchy( item ); } } </code></pre> <p>Slightly modified XAML and it works just great! Changes to the collection or properties of Current updates the TreeView accordingly.</p> <pre><code>&lt;HierarchicalDataTemplate DataType="{x:Type ui:ObservableFolderHierarchy}" ItemsSource="{Binding Children}"&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;Image Source="/UI/Resources/folder.png" Width="16" Height="16"/&gt; &lt;TextBlock Text="{Binding Current.FolderName}"/&gt; &lt;/StackPanel&gt; &lt;/HierarchicalDataTemplate&gt; </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