I have a problem with scrolling my datagrid. I am using a WPF C# application with the 4.7.2 .NET Framework. I load about 5000 datasets into a datatable, which I display with a datagrid. When I run the program through the Visual Studio 2019 compiler and scroll through the records, the result is actually good. However, if I start the program via the .exe, the whole thing hangs a bit when scrolling. I've found a few things on the forum and tried them, but it didn't work out well for me =>
<DataGrid EnableRowVirtualization="False" VirtualizingStackPanel.IsVirtualizing="False"
ScrollViewer.CanContentScroll=False />
When I try this, the scrolling result is better, but the performance when loading the database is extremely poor.
<DataGrid Width = 400, Height = 400/>
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="Height" Value="50"/>
</Style>
</DataGrid.CellStyle>
One post mentioned that the height of the data grid and the cells should be adjusted. However, that was also unsuccessful
<DataGrid VirtualizingStackPanel.VirtualizationMode="Standard"
ItemsSource="{Binding MyStuff, IsAsync=True}" />
I've had the best results so far with VirtualizingStackPanel.VirtualizationMode="Standard". Scrolling is still quite choppy, but it doesn't load for as long. Optionally, you can set the item source IsAsync=True, but that didn't really help much anymore.
Unfortunately, I haven't found a better way to avoid loss of performance and to be able to scroll smoothly. Do you have any other ideas? Kind regards
CodePudding user response:
I had simmilar issue. Try it with VirtualizingPanel.ScrollUnit="Pixel" RenderOptions.CachingHint="Cache" VirtualizingPanel.CacheLength="10" VirtualizingPanel.CacheLengthUnit="Pixel"
. You can adjust Cache Length due to your datasets. But remember to use profiler (ALT F2 IN VS2022)
CodePudding user response:
Set ScrollVIewer.CanContentScroll
to true
maybe this works for you