获取双动画的当前值 [英] Get current value of a double animation

查看:71
本文介绍了获取双动画的当前值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个故事板,在其中我使一个矩形像MPH汽车仪表中的针一样向上移动.因此,我将其从0变为60,并希望能够在变化时获取其当前值,以便可以使用该值制作数字量规.

I have a story board where I am making a rectangle move up like a needle in a MPH car gauge. So, I make it go from 0 to 60 and I want to be able to get its current value while it's changing so I can use that value to make a digital gauge.

如何从双重动画的开始到结束获取当前值?我有这样的东西:

How can I get the current value from the beginning to the end of a double animation? I have something like this:

DoubleAnimation da = new DoubleAnimation();
da.Duration = new Duration(TimeSpan.FromSeconds(5));
da.From = 0;
da.To = 60;
RotateTransform rt = new RotateTransform();
rt.CenterX = 35;
rt.CenterY = 0;
rec3.RenderTransform = rt;
rt.BeginAnimation(RotateTransform.AngleProperty, da);

当矩形向上旋转时,我试图获得该角度,但它只是返回零.

When it rotates the rectangle up I tried to get that angle but it just returned zero.

推荐答案

您一定在做错事,请考虑以下示例:

You must be doing something wrong, consider this example:

<Rectangle Width="100" Height="10" Fill="Red" HorizontalAlignment="Left" RenderTransformOrigin="1,0.5">
    <Rectangle.RenderTransform>
        <RotateTransform x:Name="rt" />
    </Rectangle.RenderTransform>
</Rectangle>
<TextBlock Text="{Binding ElementName=rt, Path=Angle}" />

rt.BeginAnimation(RotateTransform.AngleProperty, new DoubleAnimation(0, 60, TimeSpan.FromSeconds(1), FillBehavior.HoldEnd));

它显示的值很好.

如果您将 rt.Angle 分配给某个变量,该变量在该时间点将具有变换角度的值,则该变量将不更改,同时 rt.Angle 属性.

If you assign the rt.Angle to some variable that variable will have the value of the transform angle at that point in time, it will not change concurrently with the rt.Angle property.

如果您不熟悉上面代码中使用的数据绑定,则可能要查看概述.

If you are new to databinding which i used in the above code you might want to check out the overview.

这篇关于获取双动画的当前值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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