简体   繁体   中英

WP7: ListBox.ScrollIntoView smooth scrolling

How can i make smooth scrolling of content into ListBox? I tried to use ListBox.ScrollIntoView but it instantly scrolls to selected item.

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.

There's a full article about this approach here .

    <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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM