title: Grouping in ItemsControl using ItemsSource from ViewModel
body: <p>I've defined <code>ItemsControl</code> like that:</p>
  
  <pre><code>&lt;ItemsControl Grid.Row="2" Style="{StaticResource SellingDashboardToDosList}"
                BorderThickness="1" Background="#C7E8F8" HorizontalAlignment="Stretch" 
                ItemsSource="{Binding Path=ToDoList}"&gt;
      &lt;ItemsControl.GroupStyle&gt;
          &lt;GroupStyle&gt;
              &lt;GroupStyle.ContainerStyle&gt;
                  &lt;Style TargetType="GroupItem"&gt;
                      &lt;Setter Property="Template"&gt;
                          &lt;Setter.Value&gt;
                              &lt;ControlTemplate TargetType="GroupItem"&gt;
                                  &lt;GroupBox Header="{Binding Path=Model.TodoType}" &gt;
                                      &lt;ItemsPresenter /&gt;
                                  &lt;/GroupBox&gt;
                              &lt;/ControlTemplate&gt;
                          &lt;/Setter.Value&gt;
                      &lt;/Setter&gt;
                  &lt;/Style&gt;
              &lt;/GroupStyle.ContainerStyle&gt;
          &lt;/GroupStyle&gt;
      &lt;/ItemsControl.GroupStyle&gt;
  &lt;/ItemsControl&gt;
  </code></pre>
  
  <p>The <code>ItemsSource</code> is a <code>SynchronisedObservableCollection&lt;T&gt;</code> in the <code>ViewModel</code>. But this XAML doesn't produce any grouping. I assume that I should specify somehow that <code>ItemsSource</code> is groupable. But where should I specify it? </p>
  
  <p>If I would use an <code>XmlDataProvider</code> with some static data, then I could do it in a <code>CollectionViewSource</code> element like in following example: <a href="http://cromwellhaus.com/2010/03/grouping-is-crazy-easy-in-wpf/" rel="nofollow noreferrer">http://cromwellhaus.com/2010/03/grouping-is-crazy-easy-in-wpf/</a> (<a href="https://web.archive.org/web/20160602204708/http://cromwellhaus.com/2010/03/grouping-is-crazy-easy-in-wpf/" rel="nofollow noreferrer">Archived</a>). </p>
  
  <p>I've tried to do it like that:</p>
  
  <pre><code>&lt;CollectionViewSource x:Key="CollectionViewSource1" Source="{Binding Path=ToDoList}"&gt;
      &lt;CollectionViewSource.GroupDescriptions&gt;
          &lt;PropertyGroupDescription PropertyName="TodoType"/&gt;
      &lt;/CollectionViewSource.GroupDescriptions&gt;
  &lt;/CollectionViewSource&gt;
  </code></pre>
  
  <p>But then I get a runtime binding error:</p>
  
  <blockquote>
    <p>Value produced by BindingExpression is not valid for target property.;
    Value='System.Windows.Data.ListCollectionView'
    BindingExpression:Path=ToDoList;  DataItem='ToDosViewModel'
    (HashCode=40956219);  target element is 'CollectionViewSource'
    (HashCode=51380674);  target property is 'Source' (type 'Object');</p>
  </blockquote>