0

I have a Datagrid that is bound with the property ItemsSource="{Binding}" to a DataContext in the codebehind. Thats fine.

Now I would like to add a datagrid inside the RowDetailTemplate. I want to bind this inner Datagrid to a complete other source than the outer Datagrid.


I thought that I just give the inner Datagrid a Name and I have access to this inner Datagrid in the code behind, lide innerDatagrid.DataContext = …. However I have no access to this element.

How can I solve this problem??

Here is some code:

<DataGrid Name="datagrid1" ItemsSource="{Binding}" ...>
<DataGrid.RowDetailsTemplate>
    <DataTemplate>
       <StackPanel>
          <TextBlock Text="{Binding "a Property from the datagrid1 ItemSource (this works fine)"}" />
       </StackPanel>
       <StackPanel>
           <Datagrid Name="datagrid2" ItemsSource="{Binding}">
              ...
           </Datagrid>
       </StackPanel>
    </DataTemplate>
</Datagrid>

And in the code behind I normally write something like: datagrid1.DataContext = ...DataSet.Tables["tablename"].DefaultView;
With the datagrid1, it works fine. However I have no access to the datagrid2 in the RowDetails. I will bind a complete other source to the datagrid2. I suppose that the datagrid2 is not in the visual tree (?). I have no idea how to solve that problem.

ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
Andre
  • 1
  • 1
  • 1
    Post your code here and also you don't need to access element in code behind at all. That will defeat the purpose of binding. – Rohit Vats Aug 03 '14 at 10:33
  • In short: How can I bind a datatable or a List to the second datagrid2 inside the rowdetailtemplate? – Andre Aug 03 '14 at 18:41

0 Answers0