使用Expander Control显示嵌套的datagrid

时间:2022-04-07 14:31:13

We are creating a WPF application in which we have to display nested datagrid. For this, we are using expander control. But, what happen is, our internal datagrid which is displaying on clicking of expander button, gets hidden behind our Main/Parent datagrid.

我们正在创建一个WPF应用程序,我们必须在其中显示嵌套的datagrid。为此,我们使用扩展器控制。但是,发生的是,我们的内部数据网格在点击扩展器按钮时显示,隐藏在我们的主/父数据网格后面。

Following is the XAML code for datagrid:

以下是datagrid的XAML代码:

<DataGrid ItemsSource="{Binding abc}">
    <DataGrid.Columns>
       <DataGridTemplateColumn Width="*" Header="column1">
          <DataGridTemplateColumn.CellTemplate>
             <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="{Binding item}"/>
                    <Expander>                                                            
                         <Canvas>
                           <DataGrid ItemsSource="{Binding Path=xyz}">
                              <DataGrid.Columns>
                                  <DataGridTextColumn Header="column1"></DataGridTextColumn>
                                  <DataGridTextColumn Header="column1">
                              </DataGrid.Columns>
                            </DataGrid>
                         </Canvas>
                     </Expander>
                </StackPanel>
            </DataTemplate>
         </DataGridTemplateColumn.CellTemplate>
     </DataGridTemplateColumn>
</DataGrid>

Any idea to fix the above issue is highly appreciable.

任何解决上述问题的想法都非常值得注意。

1 个解决方案

#1


0  

try to suppress the canvas

试着压制画布

    <DataGrid ItemsSource="{Binding abc}" >
        <DataGrid.Columns>
            <DataGridTemplateColumn Width="*" Header="column1">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding item}"/>
                            <Expander IsExpanded="True">
                                    <DataGrid ItemsSource="{Binding Path=xyz}">
                                        <DataGrid.Columns>
                                            <DataGridTextColumn Header="column1"/>
                                            <DataGridTextColumn Header="column1"/>
                                        </DataGrid.Columns>
                                    </DataGrid>
                            </Expander>
                        </StackPanel>
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>
        </DataGrid.Columns>
    </DataGrid>

if it doesn't work can you please send a datacontext example that populate the datagrid

如果它不起作用,请发送一个填充数据网格的datacontext示例

#1


0  

try to suppress the canvas

试着压制画布

    <DataGrid ItemsSource="{Binding abc}" >
        <DataGrid.Columns>
            <DataGridTemplateColumn Width="*" Header="column1">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding item}"/>
                            <Expander IsExpanded="True">
                                    <DataGrid ItemsSource="{Binding Path=xyz}">
                                        <DataGrid.Columns>
                                            <DataGridTextColumn Header="column1"/>
                                            <DataGridTextColumn Header="column1"/>
                                        </DataGrid.Columns>
                                    </DataGrid>
                            </Expander>
                        </StackPanel>
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>
        </DataGrid.Columns>
    </DataGrid>

if it doesn't work can you please send a datacontext example that populate the datagrid

如果它不起作用,请发送一个填充数据网格的datacontext示例