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 RowDetailTemplat
e. 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.