开发者

WPF MVVM Binding to a DataTable within a DataTable

开发者 https://www.devze.com 2022-12-07 22:23 出处:网络
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.

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

精彩评论

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