title: WPF DataGrid inside DataGrid.RowDetailsTemplate
body: <p>I am trying to create a DataGrid inside a WPF DataGrid's RowDetailsTemplate.</p>
  
  <p>I have a collection of Jobs. Each Job can have one or more Employees assigned to it:</p>
  
  <pre><code>public class Job : _Base
  {
      private string _JobName = string.Empty;
      public string JobName
      {
          get { return _JobName; }
          set 
          {
              if (_JobName != value)
              {
                  _JobName = value;
                  RaisePropertyChanged("JobName");
              }
          }
      }
  
      private string _JobNumber = string.Empty;
      public string JobNumber
      {
          get { return _JobNumber; }
          set
          {
              if (_JobNumber != value)
              {
                  _JobNumber = value;
                  RaisePropertyChanged("JobNumber");
              }
          }
      }
  
      private ObservableCollection&lt;Employee&gt; _Employees;
      public ObservableCollection&lt;Employee&gt; Employees
      {
          get { return _Employees; }
          set
          {
              if (_Employees != value)
              {
                  if (_Employees != value)
                  {
                      _Employees = value;
                      RaisePropertyChanged("Employees");
                  }
              }
          }
      }
  
      public Job()
      {
          Employees = new ObservableCollection&lt;Employee&gt;();
      }
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>public class Employee : _Base
  {
      private string _EmployeeName = string.Empty;
      public string EmployeeName
      {
          get { return _EmployeeName; }
          set
          {
              if (_EmployeeName != value)
              {
                  _EmployeeName = value;
                  RaisePropertyChanged("EmployeeName");
              }
          }
      }
  
      private bool _IsChecked = false;
      public bool IsChecked
      {
          get { return _IsChecked; }
          set
          {
              if (_IsChecked != value)
              {
                  _IsChecked = value;
                  RaisePropertyChanged("IsChecked");
              }
          }
      }
  }     
  </code></pre>
  
  <p>and my XAML:</p>
  
  <pre><code>&lt;DataGrid ItemsSource="{Binding Jobs}"
              AutoGenerateColumns="False"&gt;
  
      &lt;DataGrid.Columns&gt;
          &lt;DataGridTextColumn Header="Job Name" Binding="{Binding JobName}" /&gt;
          &lt;DataGridTextColumn Header="Job Number" Binding="{Binding JobNumber}" /&gt;
      &lt;/DataGrid.Columns&gt;
  
      &lt;DataGrid.RowDetailsTemplate&gt;
          &lt;DataTemplate&gt;
              &lt;DataGrid ItemsSource="{Binding Employees}"
                          AutoGenerateColumns="False"&gt;
                  &lt;DataGridCheckBoxColumn Binding="{Binding IsChecked}"/&gt;
                  &lt;DataGridTextColumn Binding="{Binding EmployeeName}"/&gt;
              &lt;/DataGrid&gt;
          &lt;/DataTemplate&gt;
      &lt;/DataGrid.RowDetailsTemplate&gt;
  
  &lt;/DataGrid&gt;
  </code></pre>
  
  <p>When I run this and click a row, I get:</p>
  
  <p><strong><em>Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource instead</em></strong></p>
  
  <p>If I remove the inner grid's column definitions, then it doesn't error. But then it's generating the columns by itself. I need to specify the columns myself.</p>
  
  <p>What is wrong here?</p>