title: WPF DataGrid: Specify a default sort
body: <p>I've a UserControl, which basically only contains a DataGrid.
  In this DataGrid, I've a list of event(Severity - Date - Message).
  The user controls is bound through the <code>ViewModelLocator</code> of <code>MVVMLight Toolkit</code>.</p>
  
  <p>I've added two things:</p>
  
  <p>In my UserControl resources:</p>
  
  <pre><code>&lt;UserControl.Resources&gt;
      &lt;CollectionViewSource x:Key="SortedEvents" Source="{Binding Events}"&gt;
          &lt;CollectionViewSource.SortDescriptions&gt;
              &lt;componentModel:SortDescription PropertyName="EventTime" Direction="Descending"/&gt;
          &lt;/CollectionViewSource.SortDescriptions&gt;
      &lt;/CollectionViewSource&gt;
  &lt;/UserControl.Resources&gt;
  </code></pre>
  
  <p>which is used by the DataGrid:</p>
  
  <pre><code>&lt;DataGrid ItemsSource="{Binding Source={StaticResource SortedEvents}}" AutoGenerateColumns="False" &gt;
  </code></pre>
  
  <p>I also have the <code>SortedDirection</code> set on the <code>DataGridTextColumn.SortDirection</code>:</p>
  
  <pre><code>&lt;DataGridTextColumn Binding="{Binding EventTime}"  Header="Time" IsReadOnly="True" SortDirection="Descending"/&gt;
  </code></pre>
  
  <p>When I check the designer, I see the small arrow showing that the DataGrid is sorted correctly. </p>
  
  <p>But when I launch the application, the list is not sorted, the arrow is not here. If I click on the column to sort it, it sorts everything correctly, its just the default value which doesn't seems to work.</p>
  
  <p>What am I missing? (This dataGrid/column are not even named, so I cannot try to edit them through something else).</p>
  
  <p>(Initially I was only having the <code>SortDirection</code>on the <code>DataGridTextColumn</code>. Same result)</p>