I have 3 content items, two DataGrid
and a StackPanel
that all need to scroll together in a WPF application. Everything works OK with ScrollViewer
as long as I only have a small dataset, but when I get to 500 rows with 150 columns, it lags for about 8 seconds before drawing the screen. After reading this: Unreasonable WPF DataGrid Loading Time I disabled the ScrollViewer
and it loaded in just 2.5 seconds.
<ScrollViewer CanContentScroll="True"
HorizontalScrollBarVisibility="Visible"
VerticalScrollBarVisibility="Visible">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="20" />
<RowDefinition Height="22" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<DataGrid x:Name="DataGridViewHeader" CellEditEnding="ColumnNameUpdate" Grid.Row="0" HeadersVisibility="None" HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch" ItemsSource="{Binding}" CurrentCellChanged="DataGridCellChange" Grid.Column="0" DataGridCell.Selected="DataGrid_GotFocus" />
<StackPanel Orientation="Horizontal" VerticalAlignment="Top" Name="ComboBoxPanel" Grid.Row="1" Margin="0,0,0,0" HorizontalAlignment="Left" >
</StackPanel>
<DataGrid x:Name="DataGridView" Grid.Row="2" HeadersVisibility="None" HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch" ItemsSource="{Binding}" CurrentCellChanged="DataGridCellChange" Grid.Column="0"/>
</Grid>
</ScrollViewer>
The trouble is, that the ScrollViewer
offers the following layout, which allows me to rename columns at the top, use a dropdown on the second row to select DataType
of that column and then shows the data. With 150 columns, they have to all stay lined up, but performance is taking a huge hit.
While I realize that ScrollViewer
is an easy solution, is there a better way when taking performance into account?