Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you can, how about using <em>linq</em> to filter the <code>Nodes</code> collection? Then set the new collection as the datasource of your `TreeView. Smth like:</p> <pre><code>var ActiveNodes = Nodes.Where(p =&gt; p.Leaves.Any( l = l.IsActive == true)); </code></pre> <p><strong>Edit:</strong> <em>Filtering during binding</em></p> <p>I still think the first solution is the way to go but if you you might find this suggestion useful too. Change the <code>Node</code> class to:</p> <pre><code> class Node { public bool IsActiveNode { get { return Leaves.Any(p =&gt; p.IsActive); } } //Other stuff.. public ObservableCollection&lt;Leaf&gt; Leaves { get; set; } } </code></pre> <p>Then you can use a converter (see an example of converters <a href="http://www.jeff.wilcox.name/2008/07/visibility-type-converter/" rel="nofollow">here</a> in case you are not familiar) to try to show/hide the nodes.</p> <pre><code>&lt;toolkit:TreeView x:Name="MyTreeView" BorderThickness="0,0,0,0"&gt; &lt;toolkit:TreeView.ItemTemplate&gt; &lt;toolkit:HierarchicalDataTemplate ItemsSource="{Binding Nodes}"&gt; &lt;StackPanel&gt; &lt;TextBox Visibility="{Binding IsActiveNode , Converter={StaticResource VisibilityConverter}}" &gt;&lt;/TextBox&gt; &lt;/StackPanel&gt; &lt;/toolkit:HierarchicalDataTemplate&gt; &lt;/toolkit:TreeView.ItemTemplate&gt; &lt;/toolkit:TreeView&gt; </code></pre> <p>If you are worried about the performance of the first approach, I donT think latter is any better :) Maybe there s a better way, if so it d be nice to know. </p> <p><strong>EDIT 2</strong> <em>To answer your question</em> </p> <blockquote> <p>I would like to know if I have to do it that way.</p> </blockquote> <p>I think you have to change the bound source in runtime (1) or introduce a new property to the <code>Node</code> like the <em>IsActive</em> in the <code>Leaf</code> (2)</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