I have created a DataTable with an unknown number of columns. There is only one Row within the DataTable and it contains another DataTable for each cell.
CoordsDataTable = new();
foreach (var coordset in DrillDesigns.Coordinates)
{
CoordsDataTable.Columns.Add(coordset!.CoordinateType!.CoordinateType, typeof(DataTable));
}
CoordsDataTable.Rows.Add();
foreach (var coordset in DrillDesigns.Coordinates)
{
CoordsDataSet = new();
CoordsDataSet.Columns.Add("X");
CoordsDataSet.Columns.Add("Y");
CoordsDataSet.Columns.Add("Z");
CoordsDataSet.Rows.Add(coordset.X, coordset.Y, coordset.Z);
CoordsDataTable.Rows[0][coordset!.CoordinateType!.CoordinateType] = CoordsDataSet;
}
How do I bind to this in WPF MVVM? I can get the first table with autogenerated columns but I cannot bind to th开发者_如何学运维e second DataTable.
<DataGrid
x:Name="coordsDG"
ItemsSource="{Binding CoordsDataTable }"
DockPanel.Dock="Top">
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<DataGrid
ItemsSource="{Binding DataContext, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"
AutoGenerateColumns="True"
CanUserAddRows="False">
</DataGrid>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>
精彩评论