在动画期间获取对象坐标 [英] Get object coordinates during animation

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

问题描述

亲爱的朋友,

我正在像这样的标签上做一些动画:

I'm doing some animation on a label like this:

lblNews1.Content = "OLA OLA OLA OLA";
lblNews1.Margin = new Thickness(0, altura - 50, 0, 0);
lblNews1.Foreground = System.Windows.Media.Brushes.White;
TranslateTransform trans = new TranslateTransform();
lblNews1.RenderTransform = trans;
DoubleAnimation anim1 = new DoubleAnimation(largura + 10, 0 - lblSize1.Width, TimeSpan.FromSeconds(20));
trans.BeginAnimation(TranslateTransform.XProperty, anim1);

我希望在其他动画中显示此动画期间的坐标.文本框或其他标签.

I wish to display the coordinates during this animation in some other control. Textbox or another label..

我该如何实现?

谢谢您的帮助.

推荐答案

采用这种动画方式会使操作变得棘手.

Animating that way is going to make it tricky.

我没有所有变量,但您只是将标签从右移到左.

I don't have all your variables but you're just moving the label right to left.

或者可能是从左到右.

这显然不完全是您所拥有的东西,但是它使用Canvas.Left对标签进行动画处理并显示X坐标.

This is obviously not precisely what you have there but it animates the label and shows the X co-ordinate by using Canvas.Left.

        Title="MainWindow" Height="350" Width="525"
        ContentRendered="Window_ContentRendered"
        >
    <Grid>
        <Canvas>
            <Label Name="lblNews1">
                <Style TargetType="Label">
                    <Setter Property="Canvas.Left" Value="400"/>
                </Style>
            </Label>

        </Canvas>  
        <TextBlock Text="{Binding Path=(Canvas.Left), ElementName=lblNews1, Mode=TwoWay}"
                       VerticalAlignment="Bottom"
                       />
    </Grid>
</Window>

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Window_ContentRendered(object sender, EventArgs e)
        {
            lblNews1.Content = "OLA OLA OLA OLA";
            DoubleAnimation animation = new DoubleAnimation(400, 0, TimeSpan.FromSeconds(20));
            lblNews1.BeginAnimation(Canvas.LeftProperty, animation);
        }
    }


当您运行它时,标签会进行动画处理,并且其中带有x坐标的文本块当然会变成香蕉,因为它的变化相当快.


When you run it, the label animates and of course the textblock with the x co-ordinate in it goes bananas because it's changing fairly rapidly.


这篇关于在动画期间获取对象坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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