我怎样才能让内容到ListBox的平滑滚动? 我试图用ListBox.ScrollIntoView但立即滚动到选定的项目。
How can i make smooth scrolling of content into ListBox? I tried to use ListBox.ScrollIntoView but it instantly scrolls to selected item.
您可以用动画来实现这一目标 - 不幸的是,滚动水平/ VerticalOffset不能直接动画片,所以你必须在一个调解员对象动画的属性,然后进而设置所需的值。
You can use an animation to achieve that goal - unfortunately the scrolling Horizontal/VerticalOffset cannot be animated directly so you have to animate properties on a mediator object, which then in turn sets the desired values.
有一个关于这种方法这里。
<ScrollViewer x:Name="MyScroller">
<ScrollViewer.Resources>
<Storyboard x:Name="ScrollAnimation">
<!-- Animate from top to bottom -->
<DoubleAnimation x:Name="VerticalOffsetAnimantion"
Storyboard.TargetName="Mediator"
Storyboard.TargetProperty="VerticalOffset"
Duration="0:0:1">
<DoubleAnimation.EasingFunction>
<!-- Ease in and out -->
<ExponentialEase EasingMode="EaseInOut"/>
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
</Storyboard>
</ScrollViewer.Resources>