title: How to sort TreeView items using SortDescriptions in Xaml?
body: <p>I have a list of <code>Layers</code> binded to a <code>TreeView</code> where each instance has a list of <code>Effects</code>. I show them via a HierarchicalDataTemplate which works great but I am trying to sort them using <code>SortDescriptions</code>.</p>
  
  <p>I don't know how to do this in xaml but doing this sorts only the first level of items, not the sub items:</p>
  
  <pre><code>ICollectionView view = CollectionViewSource.GetDefaultView ( treeView1.ItemsSource );
  view.SortDescriptions.Add ( new SortDescription ( "Name", ListSortDirection.Ascending ) );
  </code></pre>
  
  <p>I am trying to sort them first by <code>.Color</code>, then by <code>.Name</code>.</p>
  
  <p>Any ideas?</p>
  
  <p>EDIT: I added this code:</p>
  
  <pre><code>&lt;Window.Resources&gt;
  
      &lt;CollectionViewSource x:Key="SortedLayers" Source="{Binding AllLayers}"&gt;
          &lt;CollectionViewSource.SortDescriptions&gt;
              &lt;scm:SortDescription PropertyName="Color" /&gt;
              &lt;scm:SortDescription PropertyName="Name" /&gt;
          &lt;/CollectionViewSource.SortDescriptions&gt;
      &lt;/CollectionViewSource&gt;
  
  &lt;/Window.Resources&gt;
  </code></pre>
  
  <p>But this still only does it for the first level of hierarchy. How can I specify it for each layer.Effects collection?</p>