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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With