title: How to synchronize column widths between two nested datagrids?
body: <p>I have a wpf toolkit datagrid with a few columns, then inside the row details I have another datagrid. Basically I am emulating a treelistview control (example: <a href="http://www.codeproject.com/KB/list/treelistview.aspx" rel="nofollow noreferrer">http://www.codeproject.com/KB/list/treelistview.aspx</a>) but using datagrids.</p>
  
  <p>I would like to sync the column widths of the datagrid in the row details with the column widths of the main parent datagrid.</p>
  
  <p>I tried defining a child datagrid column like this:</p>
  
  <pre><code>&lt;toolkit:DataGridTextColumn Binding="{Binding Path=Name}" Width="{Binding ElementName=mainDataGrid, Path=Columns[0].ActualWidth}" /&gt;
  </code></pre>
  
  <p>This did not work (even with some variations like Mode=OneWay).</p>
  
  <p>EDIT:</p>
  
  <p>Ok I gave up on getting the binding to work. Trying with code...
  Now, since the DataGrid doesn't fire an event for column width changed I made my own:</p>
  
  <pre><code>PropertyDescriptor pd = DependencyPropertyDescriptor.FromProperty(DataGridColumn.WidthProperty, typeof(DataGridColumn));
  pd.AddValueChanged(testColumn, new EventHandler(mainDataGrid_WidthPropertyChanged));
  
  private void mainDataGrid_WidthPropertyChanged(object sender, EventArgs e)
  {
      // this works fine, but how do I find my templated child datagrid?
  }
  </code></pre>
  
  <p>The event seems to fire correctly, but I can't seem to find my templated datagrid. Each row has a row details section, but some or all can be hidden. But still even when my row details is visible I cannot find a reference to it (always null).</p>
  
  <pre><code>DataGrid dg = mainDataGrid.FindChild(null, typeof(DataGrid)) as DataGridRow; // dg always null
  </code></pre>
  
  <p>This is using a 'FindChild' method that I know works.
  Anyone know what the problem could be? Or any other suggestions? Thanks</p>