Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF TreeView bound to ObservableCollection not updating root nodes
    text
    copied!<p>Sorry - my question is almost identical to <a href="https://stackoverflow.com/questions/1898463/wpf-bound-treeview-not-updating-root-items">this one</a> but since it didn't receive a viable answer, I am hoping that someone else has some fresh ideas.</p> <p>I have a WPF TreeView that is bound to a hierarchy of a single type:</p> <pre><code>public class Entity { public string Title { get; set; } public ObservableCollection&lt;Entity&gt; Children { get; set; } } </code></pre> <p>The Entity class implements INotifyPropertyChanged, but I have omitted this code for clarity.</p> <p>The TreeView is bound to an ObservableCollection&lt;Entity> and each Entity instance exposes a set of contained Entity instances via its Children property:</p> <pre><code>&lt;TreeView ItemsSource="{Binding Path=Entities}"&gt; &lt;TreeView.Resources&gt; &lt;HierarchicalDataTemplate DataType="{x:Type local:Entity}" ItemsSource="{Binding Path=Children}"&gt; &lt;TextBlock Text="{Binding Path=Title}" /&gt; &lt;/HierarchicalDataTemplate&gt; &lt;/TreeView.Resources&gt; &lt;/TreeView&gt; </code></pre> <p>Initially the TreeView binds as expected and correctly displays a multi-level hierarchy. Also, when the membership of one of the Children collections is programmatically modified, the changes are correctly reflected in the TreeView.</p> <p>However, changes to the membership of the root member level ObservableCollection&lt;Entity> are not reflected in the TreeView.</p> <p>Any suggestions would be appreciated.</p> <p>Thanks, Tim</p>
 

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