VirtualizingPanel in DataGrid

时光怂恿深爱的人放手 提交于 2019-12-01 05:16:52

问题


I've started exploring the Data and UI virtualization features in WPF recently and stumbled upon something strange.

I created a DataGrid's with Virtualizing enabled and filled it with a list with 1,000,000 items. This works great and amazingly fast.

<Grid>
    <DataGrid x:Name="employees" VirtualizingPanel.IsVirtualizing="True" 
                                 VirtualizingPanel.IsContainerVirtualizable="True"
                                 VirtualizingPanel.VirtualizationMode="Recycling"/>
</Grid>

However, when I nested it under a StackPanel it loads for over a minute until I get OutOfMemoryException. I've set the same VirtualizingPanel properties on the StackPanel as well but it doesn't help.

Is this behaviour intentional or am I missing something basic here? And how can I manage to support data virtualization in nested controls?


回答1:


a StackPanel is an "infinite container" (notice the quotes), in the sense that it does NOT impose a limit in the size of its children, like a Grid or DockPanel does.

What this means in terms of UI virtualization is that, since your DataGrid is not limited in Height, it will grow endlessly and render all it's items, effectively losing UI virtualization.

See MSDN: WPF Layout for more details.

The bottom line is that you need make sure you use the appropiate layout containers, depending on your needs.



来源:https://stackoverflow.com/questions/20661452/virtualizingpanel-in-datagrid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!