Reputation: 41
I have a WPF Application which contains a DataGrid. The DataGrid contains 10 DataGridTemplateColumns. I add 4 additonal DataGridTemplateColumns to it,but after that ththe DataGrid loads very slowly. I use List as its ItemSource. Please help me to solve the issue.
This is my DataGrid XAML
<DataGrid VirtualizingStackPanel.IsVirtualizing="False"
ScrollViewer.VerticalScrollBarVisibility="Visible"
ScrollViewer.CanContentScroll="True"
BorderBrush="Transparent"
ClipToBounds="True"
GridLinesVisibility="All"
ScrollViewer.HorizontalScrollBarVisibility="Visible"
HeadersVisibility="Column"
VerticalAlignment="Top" Width="600"
Name="gvGrid"
Grid.ColumnSpan="5"
Grid.Column="0"
Grid.Row="1"
Grid.RowSpan="7"
CanUserDeleteRows="True"
CanUserAddRows="False"
CanUserResizeColumns="False"
CanUserReorderColumns="False"
CanUserResizeRows="False"
IsReadOnly="True"
CellStyle="{StaticResource DataGridContentCellCentering}"
HorizontalAlignment="Left"
Height="200"
ColumnWidth="*"
EnableRowVirtualization="True"
HorizontalGridLinesBrush="#E7E5E6"
VerticalGridLinesBrush="#E7E5E6"
ColumnHeaderStyle="{StaticResource HeaderStyle}"
AlternatingRowBackground="#F6F4F5"
AutoGenerateColumns="False"
Background="{x:Null}"
CurrentCellChanged="gvGrid_CurrentCellChanged">
Thanks in Advance.
Upvotes: 1
Views: 4067
Reputation: 5666
There are a couple of precautions you can consider for improving your DataGrid
's performance.
First of all use virtualization (just set properties EnableColumnVirtualization
and EnableRowVirtualization
to true
and avoid to put your DataGrid
in a ScrollViewer
, since it nullifies virtualization's benefits). Second step, use an async binding for the ItemsSource
property, i.e.:
ItemsSource="{Binding Path=YourList, IsAsync=True}"
They should help you.
Upvotes: 4