Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does EnableColumnVirtualization in a DataGrid work?

Tags:

wpf

datagrid

Given the following Datagrid:

<DataGrid AutoGenerateColumns="False" HeadersVisibility="Column" 
        IsReadOnly="True"
        VirtualizingPanel.IsVirtualizing="true" VirtualizingPanel.VirtualizationMode="Standard"
        EnableColumnVirtualization="True"
        ItemsSource="{Binding Data, IsAsync=True}">
    <DataGrid.Columns>
        <DataGridTextColumn Header="Header1" Width="Auto" Binding="{Binding Property1}" />
        <DataGridTextColumn Header="Header2" Width="Auto" Binding="{Binding Property2, Mode=OneWay}" />
    </DataGrid.Columns>
</DataGrid>
</Grid>

Why does it not show any rows? When I remove EnableColumnVirtualization or set it to false everything is normal. EnableRowVirtualization may be added or removed without showing any issues.

Is there an explanation for this behavior?

like image 928
Gerard Avatar asked Jul 14 '15 08:07

Gerard


1 Answers

DataGrid.EnableColumnVirtualization only creates columns when there is data to display in those columns and it's visibility is set to visible. This kind of ruins the whole Visibility=Visibility.Visible expectation.

If you require there to be column headings even when there is no data, then don't enable column virtualization, but keep row virtualization.

DataGrid.EnableRowVirtualization only creates the rows that will be visible on screen. When coupled with VirtualizingPanel.VirtualizationMode=Recycling, it can really improve the amount of memory used to display visual elements in your application so that you don't hit garbage collection nearly as often.

like image 82
Berin Loritsch Avatar answered Oct 06 '22 20:10

Berin Loritsch