title: Datagrid Sorting (Still) Not Working with Entity Framework 4.0
body: <p>I'm having trouble with an application I'm writing in VS2010.  I need to display databound data on a Datagrid and allow the user to sort its contents.</p>
  
  <p>This is my situation:</p>
  
  <ol>
  <li><p>I've built a very simple SQL database with 1 table named "Question".  The table has 2 columns, "id_Question" and "QuestionText".</p></li>
  <li><p>I created an Entity model from this database.</p></li>
  <li><p>Under "Data Sources", I've dragged and dropped the "Question" Entity as a Datagrid onto my WPF window.  When run, the Datagrid populates normally with whatever is in the database.  Great.</p></li>
  <li><p>I've set the "CanUserSortColumns" and "CanUserSort" properties of the DataGrid and DataGrid columns to True.  When the column header is clicked, nothing happens, nothing sorts.</p></li>
  </ol>
  
  <p>Here is the XAML snippet:</p>
  
  <pre><code>  &lt;DataGrid AutoGenerateColumns="False" 
                EnableRowVirtualization="True" Height="200" 
                HorizontalAlignment="Left" ItemsSource="{Binding}" 
                Margin="871,126,0,0" Name="questionsDataGrid" RowDetailsVisibilityMode="VisibleWhenSelected" 
                VerticalAlignment="Top" Width="400"
                CanUserSortColumns="True"&gt;
          &lt;DataGrid.Columns&gt;
              &lt;DataGridTemplateColumn x:Name="id_QuestionColumn1" Header="id Question" Width="SizeToHeader"&gt;
                  &lt;DataGridTemplateColumn.CellTemplate&gt;
                      &lt;DataTemplate&gt;
                          &lt;Label Content="{Binding Path=id_Question}" /&gt;
                      &lt;/DataTemplate&gt;
                  &lt;/DataGridTemplateColumn.CellTemplate&gt;
              &lt;/DataGridTemplateColumn&gt;
              &lt;DataGridTextColumn x:Name="questionTextColumn1" 
                                  Binding="{Binding Path=QuestionText}" Header="Question Text" Width="300"
                                  CanUserSort="True"/&gt;
          &lt;/DataGrid.Columns&gt;
      &lt;/DataGrid&gt;
  </code></pre>
  
  <p>I have read the following among many other related articles / questions on Stack Overflow and other sites:</p>
  
  <ul>
  <li><p><a href="https://stackoverflow.com/questions/2702434/entity-framework-4-0-databinding-with-sorting-not-working">Entity Framework 4.0 Databinding with sorting not working</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/4463505/how-to-sort-datagridview-when-bound-to-a-binding-source-that-is-linked-to-an-ef4">How to sort DataGridView when bound to a binding source that is linked to an EF4 Entity</a></p></li>
  </ul>
  
  <p>Each has provided useful insights but I haven't been able to get it to work for my problem.  What do I need to write in the code behind file to get this to work properly?</p>
  
  <p>Thanks</p>