title: WPF DataGrid: Automatically re-sort on a DataGridTemplateColumn
body: <p>In WPF's DataGrid control, if you set a column to one of the default column types (like DataGridTextColumn or DataGridCheckBoxColumn), sort on that column, and then change its value, the grid will automatically be re-sorted.</p>
  
  <p>However, if you use a DataGridTemplateColumn (and allow the column to be sorted), it can be sorted, but changing the value of a cell in this column does not cause the grid is not re-sorted. <strong>How can I coax it into automatically triggering a re-sort?</strong></p>
  
  <p>XAML:</p>
  
  <pre><code>&lt;DataGrid Name="grid" AutoGenerateColumns="False"&gt;
    &lt;DataGrid.Columns&gt;
      &lt;DataGridTextColumn Header="First name" Binding="{Binding First}"/&gt;
      &lt;DataGridTemplateColumn Header="Last name" SortMemberPath="Last"&gt;
        &lt;DataGridTemplateColumn.CellTemplate&gt;
          &lt;DataTemplate&gt;
            &lt;TextBox Text="{Binding Last}"/&gt;
          &lt;/DataTemplate&gt;
        &lt;/DataGridTemplateColumn.CellTemplate&gt;
      &lt;/DataGridTemplateColumn&gt;
    &lt;/DataGrid.Columns&gt;
  &lt;/DataGrid&gt;</code></pre>
  
  <p>Binding:</p>
  
  <pre><code>ObservableCollection items = new ObservableCollection();
  grid.ItemsSource = items;
  items.Add(new Character() { First = "Homer", Last = "Simpson" });
  items.Add(new Character() { First = "Kent", Last = "Brockman" });
  items.Add(new Character() { First = "Montgomery", Last = "Burns" });</code></pre>
  
  <p>Here's my item class, just in case that's relevant:</p>
  
  <pre><code>public class Character : INotifyPropertyChanged {
      private string first, last;
      public event PropertyChangedEventHandler PropertyChanged;
      private void Notify(string name) {
          if (PropertyChanged != null)
              PropertyChanged(this, new PropertyChangedEventArgs(name));
      }
      public string First { get { return first; } set { first = value; Notify("First"); } }
      public string Last { get { return last; } set { last = value; Notify("Last"); } }
  }</code></pre>