I am having problem to bind with an inner DataGrid. The binding works with the DataGrid "Account" but not with "Record". I am using DataGrid.RowDetailsTemplate for the second Datagrid
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<DataGrid ItemsSource="{Binding AccountList}" AutoGenerateColumns="False" x:Name="Account">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding AccountNumber}" Header="Account Number" FontSize="16"/>
<DataGridTextColumn Binding="{Binding Name}" Header="Name" FontSize="16"/>
</DataGrid.Columns>
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<DataGrid ItemsSource="{Binding RecordList,Mode=TwoWay}" AutoGenerateColumns="False" x:Name="Record" IsSynchronizedWithCurrentItem="True">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding RecordNumber}" Header="Record Number" FontSize="16"/>
<DataGridTextColumn Binding="{Binding Name}" Header="Name" FontSize="16"/>
</DataGrid.Columns>
</DataGrid>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>
</Grid>
<Grid Grid.Row="1">
<TextBlock Text="Account Number:"> <TextBox Text="{Binding ElementName=Account, Path=SelectedItem.AccountNumber}" x:Name="ANr"/>
<TextBlock Text="Record Number:"> <TextBox Text="{Binding ElementName=Record, Path=SelectedItem.RecordNumber}" x:Name="RecordText"/>
</Grid>
The error message:
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=Record'. BindingExpression:Path=SelectedItem.RecordNumber; DataItem=null; target element is 'TextBox' (Name='RecordText'); target property is 'Text' (type 'String')
The first TextBox binds without a problem. The second one fails to bind.
Thank you