如何通过使用Windows Phone 7中的动画类将图像控件移动到特定的x y co ordination

时间:2013-04-06 12:47:04

标签: windows-phone-7 animation

请帮助我如何通过使用Windows Phone 7中的动画类自动将图像移动到特定的xy位置,我已经尝试过Point动画类,但是这不适用于图像控制但是对于对象工作,所以请告诉我应该用什么样的动画类在Windows Phone 7中移动图像

我的代码是

XAML

                                                           

                </PointAnimation>
            </Storyboard>
        </Canvas.Resources>
        <Image  Source="qq.jpg" Width="200" Height="100" x:Name="MyImage" Canvas.Left="10" Canvas.Top="10" />

    </Canvas>
</Grid>

C#

        private void canvas1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Point mypoint = new Point();
            mypoint.X = 10;
            mypoint.Y = 200;

            MyPointAnimation.To = mypoint;
            myStoryboard.Begin();
        }

1 个答案:

答案 0 :(得分:2)

你可以这样做:

                <Image x:Name="myImage"
                   Canvas.Left="10"
                   Canvas.Top="10"
                   Width="200"
                   Height="100"
                   Source="/Assets/qq.jpg">
                    <Image.RenderTransform>
                        <TranslateTransform />
                    </Image.RenderTransform>
                </Image>

然后在代码背后:

            TranslateTransform trans = myImage.RenderTransform as TranslateTransform;
            DoubleAnimation anima1 = new DoubleAnimation();
            anima1.To = 150;

            Storyboard.SetTarget(anima1, trans);
            Storyboard.SetTargetProperty(anima1, new
            PropertyPath(TranslateTransform.XProperty));
            // Create storyboard, add animation, and fire it up!
            Storyboard storyboard = new Storyboard();
            storyboard.Children.Add(anima1);
            storyboard.Begin();