WP7 ScrollViewer 以编程方式滚动背景 ScrollViewer 与前 ScrollViewer 同步 [英] WP7 ScrollViewer programatically scroll a background ScrollViewer in sync with front ScrollViewer

查看:20
本文介绍了WP7 ScrollViewer 以编程方式滚动背景 ScrollViewer 与前 ScrollViewer 同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个动画,当用户滚动FrontScroll"时,应用程序会自动以相同的速度将相同大小的BackgroundScroll"滚动到相同的偏移量.在前后滚动之间分层是我想保持静态的图像.中间的图像仅占屏幕的 1/4,其余图像在 png 中是透明的.我正在尝试创建当用户滚动时其他图像逐渐出现在静态图像上方和后面的效果.

I am trying to create an animation whereby when a user Scrolls the "FrontScroll" the app automatically scrolls "BackgroundScroll", of the same size, to the same offset at the same rate. Layered in-between the front and background scroll is an image I would like to remain static. The middle image only fills 1/4 of the screen, the rest of the image is transparent in the png. I am trying to create the effect that other images appear gradually over and behind the static image when the user scrolls.

目前我在 ManipulationCompleted 上有一个有效的事件,但是它会产生非常紧张"的效果,因为在用户从屏幕上抬起手指之前,背景滚动不会滚动到位置.我想让动画即时,无论操作是否完成,从而使 2 ScrollViewers 保持完美同步.目前,当用户轻弹"ScrollViewer 移动更远的距离时,ManipulationCompleted 事件不会触发,因此两个 ScrollViewer 变得不同步.我也尝试过 MouseWheel、MouseLeave、MouseMove 事件,但都没有达到我想要的效果.

Currently I have an event on ManipulationCompleted which works, however it creates a very "jittery" effect, in that the background scroll does not scroll to position until the user lifts their finger from the screen. I would like to make the animation instant, whether the manipulation has completed on not, thus keeps the 2 ScrollViewers in perfect sync. Also at present, when a users "Flicks" the ScrollViewer to move a greater distance, the ManipulationCompleted event does not fire, thus the 2 ScrollViewers become out of sync. I have also tried the MouseWheel, MouseLeave, MouseMove events but none get the effect I am looking for.

有谁知道我正在尝试使用 Windows Phone 7.5 中的当前 API 是否可行,如果有任何指示我如何做到这一点将不胜感激?

Does anyone know if what I am trying to do is possible with the current API's in Windows Phone 7.5 and if so any pointers to how I can do this would be much appreciated?

我当前的 XAML 和 CodeBehind 事件如下.

My Current XAML and CodeBehind events are below.

        <ScrollViewer HorizontalAlignment="Center" Margin="0,0,0,0" Name="backgroundScroll" VerticalAlignment="Top"  Background="Transparent" MaxHeight="Infinity">
                <Image HorizontalAlignment="Center" Height="2000" Stretch="Fill" Source="background@2x.png" />
        </ScrollViewer>

        <Image Source="MiddleStatic@2x.png" HorizontalAlignment="Center" Name="MiddleStatic" Stretch="Fill" VerticalAlignment="Top" Margin="-1,-1,0,0" />

        <ScrollViewer   HorizontalAlignment="Center" Name="FrontScroll" VerticalAlignment="Top" MaxHeight="Infinity" MinHeight="0"  ManipulationCompleted="FrontScroll_ManipulationCompleted">
            <StackPanel Background="#00000000">
                <Image Height="2000" Source="FrontScrollImage@2x.png" HorizontalAlignment="Center" Name="FrontScroll" Stretch="Fill" />
            </StackPanel>
        </ScrollViewer>
    </Grid>


    private void FrontScroll_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
    {
        backgroundScroll.ScrollToVerticalOffset(((ScrollViewer)sender).VerticalOffset);
    }

推荐答案

很遗憾因为 WP7 ScrollViewer 没有 Scroll 事件,不知道有没有使两个 ScrollViewer 保持同步的平滑"方式.

Unfortunately because there is no Scroll event for the WP7 ScrollViewer, I am not sure if there is a "smooth" way to keep the two ScrollViewers in sync.

有一种方法可以使 ScrollViewers 保持同步,但是 - 创建一个 DispatcherTimer,并将 Interval 属性设置为一个小的 TimeSpan;例如 0.2 秒.在 Tick 事件处理程序中,将第二个滚动查看器的 VerticalOffset 设置为第一个滚动查看器的垂直偏移(就像您在 ManipulationCompleted 事件中所做的那样).

There is a way to keep the ScrollViewers in sync, however - create a DispatcherTimer, and set the Interval property to a small TimeSpan; 0.2 seconds for example. In the Tick event handler, set the 2nd scroll viewer's VerticalOffset to the first scroll viewer's vertical offset (like you are doing in the ManipulationCompleted event).

它仍然不会流畅,但定时器触发应该保持滚动同步.

It still won't be smooth, but the timer firing should keep the scrolling in sync.

这篇关于WP7 ScrollViewer 以编程方式滚动背景 ScrollViewer 与前 ScrollViewer 同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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