title: Change DataGrid cell content/template on row select
body: <p>The behavior I am aiming for is: I have a data grid with a single column. It is bound to a list of items which contain various information about a person. When not selected, the row simply displays the person's name. When the row is selected (i.e. clicked on), I was to show more information about the person.</p>
  
  <p>My first attempt was to use a DataGridTemplateColumn where the CellTemplate is a ContentControl. The style of the ContentControl is determined by the status of the selected row.</p>
  
  <p>My style:</p>
  
  <pre><code>&lt;DataTemplate x:Key="NotSelectedTemplate"&gt;
      &lt;TextBlock Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContentControl}, Path=DataContext.PatientName.FormattedName, Mode=OneWay, BindsDirectlyToSource=True, UpdateSourceTrigger=PropertyChanged}" /&gt;
  &lt;/DataTemplate&gt;
  
  &lt;DataTemplate x:Key="SelectedTemplate"&gt;
      &lt;TextBlock Height="60" Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContentControl}, Path=DataContext.PatientName.FormattedName, Mode=OneWay, BindsDirectlyToSource=True, UpdateSourceTrigger=PropertyChanged}" /&gt;
     &lt;/DataTemplate&gt;
  
  &lt;Style x:Key="SelectableContentStyle" TargetType="{x:Type ContentControl}"&gt;
      &lt;Style.Triggers&gt;
          &lt;DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}}, Path=IsSelected}" Value="False"&gt;
              &lt;Setter Property="ContentTemplate" Value="{StaticResource NotSelectedTemplate}" /&gt;
          &lt;/DataTrigger&gt;
          &lt;DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}}, Path=IsSelected}" Value="True"&gt;
              &lt;Setter Property="ContentTemplate" Value="{StaticResource SelectedTemplate}" /&gt;
          &lt;/DataTrigger&gt;
      &lt;/Style.Triggers&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p>My datagrid columns:</p>
  
  <pre><code>&lt;DataGrid.Columns&gt;
      &lt;DataGridTemplateColumn Width="*"&gt;
          &lt;DataGridTemplateColumn.CellTemplate&gt;
              &lt;DataTemplate&gt;
                  &lt;ContentControl Style="{StaticResource SelectableContentStyle}" /&gt;
               &lt;/DataTemplate&gt;
          &lt;/DataGridTemplateColumn.CellTemplate&gt;
      &lt;/DataGridTemplateColumn&gt;
  &lt;/DataGrid.Columns&gt;
  </code></pre>
  
  <p>This approach <em>works</em>, however the binding in each DataTemplate is pretty ugly. I am relatively inexperienced at WPF, so I'm sure there must be a much better way to implement this.</p>
  
  <p>Basically,
  1) Is there a better way to acheive this behavior?
  2) Is there a better way to bind to the DataTemplate so I am not chasing RelativeSources any time I want to access a property?</p>