title: How to display DataGrid inside DataGrid RowDetailsTemplate?
body: <p>I want to add a single row <code>DataGrid</code> inside another <code>DataGrid</code>s row details template.</p>
  <p>This is my XAML:</p>
  <pre><code>&lt;DataGrid  x:Name=&quot;dataGrid&quot; Margin=&quot;10,100,10,96&quot; PreviewKeyDown=&quot;dataGrid_PreviewKeyDown&quot; AutoGenerateColumns=&quot;False&quot; ItemsSource=&quot;{Binding }&quot; AlternatingRowBackground=&quot;AliceBlue&quot; CellEditEnding=&quot;onCellEditEnding&quot;  SelectedItem=&quot;{Binding SelectedItem}&quot;  &gt;
  
      &lt;DataGrid.Columns&gt;
          &lt;DataGridTextColumn Width=&quot;*&quot; Header=&quot;No&quot; Binding= &quot;{Binding Path=Id, Mode=TwoWay}&quot; IsReadOnly=&quot;True&quot; /&gt;
          &lt;DataGridTextColumn Width=&quot;*&quot; Header=&quot;Barcode&quot; Binding= &quot;{Binding Path=Barcode, Mode=TwoWay}&quot;  /&gt;
  
          &lt;DataGridTextColumn  Width=&quot;*&quot; Header=&quot;Item&quot; Binding= &quot;{Binding Path=Item, Mode=TwoWay}&quot; IsReadOnly=&quot;True&quot;/&gt;
          &lt;DataGridTextColumn  Width=&quot;*&quot; Header=&quot;Qty&quot; Binding= &quot;{Binding Path=Qty, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}&quot;/&gt;
          &lt;DataGridTextColumn  Width=&quot;*&quot; Header=&quot;Mrp&quot; Binding= &quot;{Binding Path=Mrp, Mode=TwoWay}&quot; IsReadOnly=&quot;True&quot;/&gt;
          &lt;DataGridTextColumn  Width=&quot;*&quot; Header=&quot;Discount&quot; Binding= &quot;{Binding Path=Discount, Mode=TwoWay}&quot; IsReadOnly=&quot;True&quot;/&gt;
          &lt;DataGridTextColumn  Width=&quot;*&quot; Header=&quot;Cgst&quot; Binding= &quot;{Binding Path=Cgst, Mode=TwoWay}&quot; IsReadOnly=&quot;True&quot;/&gt;
          &lt;DataGridTextColumn  Width=&quot;*&quot; Header=&quot;Sgst&quot; Binding= &quot;{Binding Path=Sgst, Mode=TwoWay}&quot; IsReadOnly=&quot;True&quot;/&gt;
          &lt;DataGridTextColumn  Width=&quot;*&quot; Header=&quot;Amount&quot; Binding= &quot;{Binding Path=Amount, Mode=OneWay ,UpdateSourceTrigger=PropertyChanged}&quot; IsReadOnly=&quot;True&quot;/&gt;
          &lt;DataGridTextColumn  Width=&quot;*&quot; Header=&quot;Salesman&quot; Binding= &quot;{Binding Path=Salesman, Mode=TwoWay}&quot; IsReadOnly=&quot;True&quot;/&gt;
          &lt;DataGridTemplateColumn Header=&quot;Delete&quot;&gt;
              &lt;DataGridTemplateColumn.CellTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;Button Content=&quot;X&quot; Click=&quot;Button_Click&quot;/&gt;
                  &lt;/DataTemplate&gt;
              &lt;/DataGridTemplateColumn.CellTemplate&gt;
          &lt;/DataGridTemplateColumn&gt;
      &lt;/DataGrid.Columns&gt;
      &lt;DataGrid.RowDetailsTemplate &gt;
          &lt;DataTemplate&gt;
              &lt;DataGrid x:Name=&quot;RowDetailsDataGrid&quot; AutoGenerateColumns=&quot;False&quot;&gt;
                  &lt;DataGrid.Columns&gt;
                      &lt;DataGridTextColumn Width=&quot;*&quot; Binding=&quot;{Binding Details}&quot;  /&gt;
                      &lt;DataGridTextColumn Width=&quot;*&quot; Binding=&quot;{Binding CgstDetails}&quot;  /&gt;
                      &lt;DataGridTextColumn Width=&quot;*&quot; Binding=&quot;{Binding SgstDetails}&quot;  /&gt;
                      &lt;DataGridTextColumn Width=&quot;*&quot; Binding=&quot;{Binding DiscountDetails}&quot;/&gt;
                  &lt;/DataGrid.Columns&gt;
                  
              &lt;/DataGrid&gt; 
              
          &lt;/DataTemplate&gt;
      &lt;/DataGrid.RowDetailsTemplate&gt;
  &lt;/DataGrid&gt;
  </code></pre>
  <p>This is (roughly) my code-behind:</p>
  <pre><code>ObservableCollection&lt;TableData&gt; tableData = new ObservableCollection&lt;TableData&gt;();
  
  public MainWindow()
  {
      InitializeComponent();
  
      dataGrid.DataContext = tableData;
      
  }
  
  public class TableData : INotifyPropertyChanged
  {
      public int Id { get; set; }
      public int No { get; set; }
  
    
      public string Details { get; set; }
      public string CgstDetails { get; set; }
  
      public string SgstDetails { get; set; }
      public string DiscountDetails { get; set; }
      public string Barcode { get; set; }
      public string Item { get; set; }
      private double qty;
      public double Qty {
          get { return qty; }
          set
          {
              qty = value;
              OnPropertyChanged(&quot;Qty&quot;);
              
          }
      }
      public double Mrp { get; set; }
      public double Discount { get; set; }
      public double Cgst { get; set; }
      public double Sgst { get; set; }
      private double amount; // field
  
      public double Amount
      {
          get { return amount; }
          set { 
              amount = (Qty * Mrp) + ((Cgst / 100) * (Mrp * Qty)) + ((Sgst / 100) * (Mrp * Qty));
              OnPropertyChanged(&quot;Amount&quot;);
          }
      }
  
      public int Salesman { get; set; }
  
      public event PropertyChangedEventHandler PropertyChanged;
      private void OnPropertyChanged(String propertyName)
      {
          if (PropertyChanged != null)
              PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
          
          
      }
  
      public bool RowAdded{ get; set; }
  }
  
  private void onCellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
  {
      var rowFetched = new TableData()
      {
          Id = currentRowIndex + 1,
          No = currentRowIndex + 1,
          Barcode = item.Barcode,
          Qty = item.Qty,
          Mrp = item.Mrp,
          Item = item.Item,
          Discount = item.Discount,
          Cgst = item.Cgst,
          Sgst = item.Cgst,
          Amount = item.Amount,
          Salesman = item.Salesman,
          Details = item.Details,
          DiscountDetails = item.DiscountDetails,
          CgstDetails = item.CgstDetails,
          SgstDetails = item.SgstDetails,
          RowAdded = true
      };
      
      tableData.Insert(currentRowIndex, rowFetched);
  }
  </code></pre>
  <p>This is not working. Instead of a <code>DataGrid</code> I have just put a <code>TextBlock</code> inside  <code>WrapPanel</code> (see the code below) and the data-binding is working perfectly and the data is shown in the row details, but I want it to be a row (<code>DataGrid</code>) instead of a <code>WrapPanel</code>.</p>
  <pre><code>&lt;DataGrid.RowDetailsTemplate &gt;
      &lt;DataTemplate&gt;
          &lt;WrapPanel Background=&quot;LightGray&quot;&gt;
              &lt;Border BorderBrush=&quot;Black&quot; BorderThickness=&quot;1&quot; Width=&quot;355&quot; Padding=&quot;40 0 0 0&quot; &gt;
                  &lt;TextBlock FontSize=&quot;16&quot; Foreground=&quot;MidnightBlue&quot; Text=&quot;{Binding Details}&quot; VerticalAlignment=&quot;Center&quot; /&gt;
              &lt;/Border&gt;
              &lt;Border BorderBrush=&quot;Black&quot; BorderThickness=&quot;1&quot; Width=&quot;71&quot;&gt;
                  &lt;TextBlock FontSize=&quot;16&quot; Foreground=&quot;MidnightBlue&quot; Text=&quot;{Binding CgstDetails}&quot; VerticalAlignment=&quot;Center&quot; /&gt;
              &lt;/Border&gt;
              &lt;Border BorderBrush=&quot;Black&quot; BorderThickness=&quot;1&quot;  Width=&quot;71&quot;&gt;
                  &lt;TextBlock FontSize=&quot;16&quot; Foreground=&quot;MidnightBlue&quot; Text=&quot;{Binding SgstDetails}&quot; VerticalAlignment=&quot;Center&quot; /&gt;
              &lt;/Border&gt;
              &lt;Border BorderBrush=&quot;Black&quot; BorderThickness=&quot;1&quot;  Width=&quot;71&quot;&gt;
                  &lt;TextBlock FontSize=&quot;16&quot; Foreground=&quot;MidnightBlue&quot; Text=&quot;{Binding DiscountDetails}&quot; VerticalAlignment=&quot;Center&quot; /&gt;
              &lt;/Border&gt;
              &lt;Border BorderBrush=&quot;Black&quot; BorderThickness=&quot;1&quot;  Width=&quot;188&quot;&gt;
                  &lt;TextBlock FontSize=&quot;16&quot; Foreground=&quot;MidnightBlue&quot; VerticalAlignment=&quot;Center&quot; /&gt;
              &lt;/Border&gt;
          &lt;/WrapPanel&gt; 
      &lt;/DataTemplate&gt;
  &lt;/DataGrid.RowDetailsTemplate&gt;
  </code></pre>
  <p>If anyone could help?</p>