在按下按钮或任何其他事件时在 Silverlight 中反转动画

发布于 2024-09-09 01:31:17 字数 598 浏览 5 评论 0原文

如何在 Silverlight 中反转事件中的双动画?例如,假设我有一个椭圆作为路径,并且我正在无限循环中沿着该路径移动形状。如果我按下按钮,我想反转旋转方向(顺时针 <-> 逆时针)。

更具体地说,我使用的是 SL4 中新增的 PathListBox 对象。它有一个从 0 到 100%(双 0 - 1)的 start 属性,它将把第一个项目放置在路径上的指定位置。通过将此属性从 0 设置为 1 以及从 1 设置为 0,我可以使对象顺时针和逆时针旋转。

假设我有一个按钮,按下按钮时,我想反转方向。我该如何去做呢?我尝试暂停动画并交换动画的“To”和“From”值并恢复动画,但这会导致动画跳跃。因此,如果它位于椭圆上的“3 点钟”位置,则会跳至“9 点钟”并从那里向后移动。我尝试执行诸如将故事板的 CurrentTime 属性设置为“持续时间 - CurrentTime”之类的操作,但该属性似乎不可设置。

那么,总而言之,关于如何按需反转动画有什么想法吗?

PS:我知道有一个 PathListBoxUtils 为 PathListBox 提供滚动行为,但这并不能完全实现我想要的。或者换句话说,我希望修改 PathListBoxUtils 以拥有无限旋转、可逆的轮播,而不是一次滚动一个项目。

How would I reverse a double animation in Silverlight on an event? For example, lets say I have an ellipse as a path and I am moving a shape along this path in an infinite loop. If I press a button, I want to reverse the direction of the spin (clockwise <-> counterclockwise).

To be more specific, I am using the PathListBox object that is new in SL4. It has a start property from 0 to 100% (double 0 - 1) that will place the first item at the specified location along the path. By animating this property from 0 to 1 and 1 to 0, I can make an object spin clockwise and counter clockwise.

Lets say I have a button and on the button press, I want to reverse the direction. How do I go about doing it? I've tried pausing the animation and swapping the To and From values of the animation and resuming it, but this causes the animation to jump. So if its at "3 o'clock" on the ellipse, it jumps to "9 o'clock" and goes backwards from there. I tried doing something like setting the storyboard's CurrentTime property to "Duration - CurrentTime", but that property doesn't seem to be settable.

So, in conclusion, any ideas about how to reverse an animation on demand?

PS: I know there is a PathListBoxUtils that provides scroll behaviors for PathListBox, but that doesn't quite implement what I want. Or to put it another way, I am looking to modify the PathListBoxUtils to have an infinitely rotating, reversible carousel rather than scrolling one item at a time.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沉睡月亮 2024-09-16 01:31:17

好吧,我让它工作的方法是暂停动画,交换 To 和 From 值,并使用 Seek 方法将动画向前移动一定的量。我需要它前进的量是“Duration.TimeSpan() - GetCurrentTime()”,但访问 Duration 似乎会抛出异常(操作对于对象的当前状态无效)。

目前,我只是硬编码了测试的持续时间值,并且似乎工作正常。我想对于真正的实现,持续时间可以绑定到某个值,并且计算也可以使用该值。

Ok, the way I got it working was by pausing the animation, swapping the To and From values, and using the Seek method to move the animation forward by a set amount. The amount I needed it to move forward is "Duration.TimeSpan() - GetCurrentTime()", but accessing Duration seems to throw an exception (Operation not valid for the current state of the object).

For now, I just hard coded the Duration value for a test and seems to be working fine. I guess for a real implementation the Duration can be bound to some value and the calculation can use that value too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文