Reputation: 5796
I have a DataGrid
with 10-15 columns which can have around 100-200 rows. The datagrid is placed within a Tab control ( which is not in focus by default ).
I tried to virtualize the DataGrid but when I click the tab containing the DataGrid, the program freezes for like 4-5 seconds, and then the tab opens displaying the datagrid. After that the rows seem to scroll fast which is good, but the columns still behave slow like un-virtualized.
When I remove the code to virtualize (last 4 options in DataGrid
tag), the grid displays immediately but scrolls very slow and lags.
The following is my datagrid code:
<DataGrid Name="xDataGridFieldConfig"
FrozenColumnCount ="1"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
VerticalAlignment="Stretch"
Style="{DynamicResource FieldConfigDataGridHeaderStyle}"
AutoGenerateColumns="False"
CanUserResizeColumns="False"
CanUserResizeRows="False"
CanUserReorderColumns="False"
SelectionMode="Single"
GridLinesVisibility="Horizontal"
HorizontalGridLinesBrush="#cbcaca"
HeadersVisibility="Column" ItemsSource="{Binding FieldConfigCollection}"
VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Visible"
VirtualizingPanel.IsVirtualizingWhenGrouping="True"
VirtualizingPanel.VirtualizationMode="Standard"
VirtualizingPanel.IsVirtualizing="True"
ScrollViewer.CanContentScroll="False">
<DataGrid.Columns>
<DataGridTextColumn Header="S No." Binding="{Binding Path=ID}" IsReadOnly="True" Width="80"/>
<!-- using template for custom checkbox -->
<DataGridTemplateColumn Header="EN" IsReadOnly="False">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<flatcheckbox:FlatCheckBox x:Name="xFlatCheckBoxFieldConfigEN" Margin="0" IsChecked="{Binding Path=Enabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<flatcheckbox:FlatCheckBox x:Name="xFlatCheckBoxFieldConfigEN" Margin="0" IsChecked="{Binding Path=Enabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Group" Width="150">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Name="xTextBlockFieldConfigGroup" Text="{Binding Path=Group, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<TextBox Name="xTextBlockFieldConfigGroup" IsEnabled="{Binding Enabled}" Text="{Binding Path=Group, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Padding="0" />
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
<!-- 10 similar text-only editable rows -->
</DataGrid.Columns>
</DataGrid>
Is there anything wrong I'm doing ? How to make the datagrid to be displayed immediately as soon as I open the tab.
Upvotes: 2
Views: 738