2

我有一个ListBox包含两列的列 - 第一列包含一个切换按钮,第二列包含一个Expander包含多个控件的列。如果expander折叠起来,则作品的整体滚动ListBox效果很好。但是,如果Expander打开并且扩展器包含大量项目,ListBox则会滚动整个行大小,通常不会显示expander列表的一部分。

这类似于在列表框中放置一个大于列表框可视区域的图像。在这种情况下,如果您单击滚动条,您可能希望“逐步”向下移动图像,而不是一键将其滚动到屏幕之外。

ListBox正如我所描述的那样,是否有允许部分滚动的设置?MylistBox是在 a 中定义的xaml,控件是通过 C# 代码添加的。

4

1 回答 1

6

Have you tried turning on smooth scrolling by setting ScrollViewer.CanContentScroll to false? This is what controls whether the ScrollViewer will scroll an item at a time, or smoothly with partial items available.

"ScrollViewer currently allows two scrolling modes: smooth pixel-by-pixel scrolling (CanContentScroll = false) or discrete item-by-item scrolling (CanContentScroll = true). Currently WPF supports UI virtualization only when scrolling by item. Pixel-based scrolling is also called 'physical scrolling' and item-based scrolling is also called 'logical scrolling'." (From this answer).

If you have a lot of items in your ListBox, this may not be an ideal solution, however, because it turns off Virtualization, and therefore may have a performance impact. Take a look at this answer to see more about smooth scrolling and virtualization. (One answer suggests a hack that allows for smooth scrolling and virtualization).

于 2013-03-01T16:43:52.607 回答