WPF DataGrid 的平滑滚动 [英] Smooth scrolling for WPF DataGrid

查看:32
本文介绍了WPF DataGrid 的平滑滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 WPF 数据网格,我所做的唯一修改是:

I am using WPF datagrid, only modification I have in place is:

    <toolkit:DataGridTextColumn.ElementStyle>
       <Style TargetType="TextBlock">
       <Setter Property="TextWrapping" Value="Wrap"/>
      </Style>
    </toolkit:DataGridTextColumn.ElementStyle>

我做了这个修改,所以如果单元格内容更长,它们会拉伸行高,不会隐藏任何文本.问题在于 DataGrid 的滚动行为 - 它在滚动时跳转整行,如果行高于一行,则根本无法正常工作 - 滚动条在滚动时抖动等.

I have this modification so if the cell contents are longer, they stretch the line height, no text is hidden. Problem is with DataGrid's scrolling behaviour - it jumps whole lines when scrolling, which does not work well at all if the row is higher than one line - scrollbar is jerking on scrolling etc.

有没有办法让 WPF DataGrid 滚动平滑"而不是逐行滚动?

Is there any way to make WPF DataGrid scroll "smoothly" and not line by line?

谢谢

推荐答案

我没有明确地使用 DataGrid,但事实上使用 ScrollViewer.CanContentScroll=False 替换了默认的 ItemsPanelTemplate 使用带有常规 StackPanelVirtualizedStackPanel.它会平滑滚动,但即使它不可见,它也会呈现每个项目.

I haven't played with the DataGrid explicitly, but it is factual that using ScrollViewer.CanContentScroll=False swaps out the default ItemsPanelTemplate which uses the VirtualizedStackPanel with a regular StackPanel. It will scroll smoothly, but it will be rendering every item even if it's not visible.

如果您要处理复杂的可视化树或大型数据集,这绝对会降低性能.

This can absolutely kill performance if you're dealing with either a complex visual tree or large datasets.

这篇关于WPF DataGrid 的平滑滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆