Datagrid虚拟化中的DataGrid [英] DataGrid inside Datagrid virtualization

查看:142
本文介绍了Datagrid虚拟化中的DataGrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在DataGrid内创建一个DataGrid.它可以工作,但是我对虚拟化有疑问. 使用一个DataGrid,RowVirtualization可以正常工作.现在,当我在一个DataGrid中创建一个DataGrid时,内部数据网格的虚拟化将不起作用,并且加载多行项目需要很长时间.我认为问题在于外部数据网格完全加载了一行,而在这一行内部有一个包含很多行的数据网格,而RowVirtualization无法正常工作.

I need to create a DataGrid inside a DataGrid. It works but I have a problem with the virtualization. With one DataGrid, the RowVirtualization works fine. Now, when I create a DataGrid inside a DataGrid, the virtualization from the inner datagrid doesn't work and it takes very long to load an item with many rows. I think the problem is the outer datagrid which loads one row completely and inside this row there is the datagrid with a lot of rows and the RowVirtualization doesn't work.

有人知道如何解决该问题吗?

Does anyone have an idea how to fix the problem?

<DataGrid x:Name="TestsGroupsDataGrid" Grid.Row="0" DataContext="{Binding TestsGroupsViewModel}" 
            AutoGenerateColumns="False" 
            HeadersVisibility="None" 
            ItemsSource="{Binding TestsGroups}" 
            SelectionMode="Extended" 
            SelectionUnit="CellOrRowHeader" 
            GridLinesVisibility="None" BorderThickness="0,0,0,0" 
            ScrollViewer.CanContentScroll="True" 
            EnableRowVirtualization="True" 
            EnableColumnVirtualization="True"
            VirtualizingPanel.VirtualizationMode="Standard"
            VirtualizingPanel.ScrollUnit="Pixel"
            VirtualizingPanel.IsVirtualizing="True"
            VirtualizingPanel.CacheLengthUnit="Pixel"
            >
    <DataGrid.Columns>
        <DataGridTemplateColumn Header="DataGridsInside" IsReadOnly="True" Width="*">
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <dataGridInDataGrid:TestsGroupControl x:Name="TestsGroup" 
                                                            AutoGenerateColumns="False" 
                                                            ItemsSource="{Binding Tests}" 
                                                            SelectionMode="Extended" 
                                                            SelectionUnit="CellOrRowHeader"
                                                            GridLinesVisibility="Horizontal" 
                                                            ScrollViewer.CanContentScroll="True" 
                                                            EnableRowVirtualization="True" 
                                                            EnableColumnVirtualization="True"
                                                            VirtualizingPanel.VirtualizationMode="Standard"
                                                            VirtualizingPanel.ScrollUnit="Pixel"
                                                            VirtualizingPanel.IsVirtualizing="True"
                                                            VirtualizingPanel.CacheLengthUnit="Pixel"
                                                            />
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>
    </DataGrid.Columns>
</DataGrid>

推荐答案

可以尝试固定内部数据网格的高度吗? 这样,仅显示其中一部分,并且在其中启用了滚动. 这将允许对内部数据网格进行虚拟化,因为一次仅呈现其中一部分,其余部分将在滚动期间动态呈现,这将提高加载数据网格的速度.

Can you try fixing the height of the inner datagrid. That way only a portion of it would be displayed with scrolling enabled inside it. This will allow virtualization of the inner datagrid since only a portion of it is rendered at a time and the rest would be dynamically rendered during scrolling and it will increase the speed with which your datagrid's are loaded.

这篇关于Datagrid虚拟化中的DataGrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆