开发者

WPF MVVM Binding to a DataTable within a DataTable

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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜