Skip to content

ListBox 虚拟化时需要注意的一些小问题

Published: at 00:00

在需要使用 ListBox 加载大量数据时,可以考虑开启虚拟化,但需要注意的是,虚拟化不一定能开启成功。

以下是一些原因:

<ControlTemplate TargetType="ListBox">
<Border SnapsToDevicePixels="True">
<ScrollViewer CanContentScroll="True">
<ItemsPresenter SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
</ScrollViewer>
</Border>
</ControlTemplate>

WPF ListBox 像素滚动

放ListBox的容器必须是有限高度的,不能是 StackPanel 这样,否则 ScrollViewer 是不会出现哒。

以下是其它的一些参考文章:

获取视觉树中的元素:

ListboxElementName.GetFirstVisualChild<ScrollViewer>();

Accessing the ScrollViewer of a ListBox from C#


原文链接: https://blog.jgrass.cc/posts/listbox-scrollviewer/

本作品采用 「署名 4.0 国际」 许可协议进行许可,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接。