通过c#windows phone创建动画 [英] Creating Animation Through c# windows phone

查看:44
本文介绍了通过c#windows phone创建动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我想在Windows手机中创建动画我可以通过Expression混合创建动画但我想通过c#代码创建动画但我已经尝试了很多但它不在这里工作我想从右端移动矩形左边只有x坐标,但它正在发出错误请帮帮我



<前lang =c#>矩形r = new Rectangle();
r.Fill = new SolidColorBrush(Colors.Purple);
r.Width = 100 ;
r.Height = 100 ;
r.Name = rectange;
LayoutRoot.Children.Add(r);
Storyboard sb = new Storyboard();
DoubleAnimation fadeInAnimation = new DoubleAnimation();
fadeInAnimation.From = 340 ;
fadeInAnimation.To = 0 ;
fadeInAnimation.Duration = new 持续时间(TimeSpan.FromSeconds( 1 0 ));
Storyboard.SetTarget(fadeInAnimation,r);
Storyboard.SetTargetProperty(fadeInAnimation, new PropertyPath( (UIElement.RenderTransform)(CompositeTransform.TranslateX)。));
sb.Children.Add(fadeInAnimation);
sb.Begin();



它在sb.begin()中引发错误;

解决方案

请试试这个代码





//创建一个红色矩形,它将成为动画的目标

//。

Rectangle myRectangle = new Rectangle();

myRectangle.Width = 200;

myRectangle.Height = 200;

Windows.UI.Color myColor = Windows.UI.ColorHelper.FromArgb(255,255,0,0);

SolidColorBrush myBrush = new SolidColorBrush();

myBrush.Color = myColor;

myRectangle.Fill = myBrush;



//创建转换

TranslateTransform moveTransform = new TranslateTransform();

moveTransform.X = 0;

moveTransform.Y = 0;

myRectangle.RenderTransform = moveTransform;





//将矩形添加到树中。

LayoutRoot.Children.Add(myRectangle);

//创建一个2秒的持续时间。 />
持续时间=新的持续时间(TimeSpan.FromSeconds(1.0));

//创建两个DoubleAnimations并设置它们的属性。

DoubleAnimation myDoubleAnimationX = new DoubleAnimation();

Storyboard sb = new Storyboard();

sb.Duration = duration;

sb.Children.Add(myDoubleAnimationX) ;

Storyboard.SetTarget(myDoubleAnimationX,moveTransform);

Storyboard.SetTargetProperty(myDoubleAnimationX,X);



myDoubleAnimationX.To = 0;

myDoubleAnimationX.From = 340;



//使故事板成为资源。 />
LayoutRoot.Resources.Add(unique_id,sb);



//开始动画。

sb .Begin();





谢谢,

Bilaal


Hi i want to create animation in windows phone i can able to create animation through Expression blend but i want to create animation through c# code but i have tried a lot but its not working here i want to move a rectange from right end to left end only in x coordinate but it was rasing an error please help me

Rectangle r = new Rectangle();
           r.Fill = new SolidColorBrush(Colors.Purple);
           r.Width = 100;
           r.Height = 100;
           r.Name = "rectange";
           LayoutRoot.Children.Add(r);
           Storyboard sb = new Storyboard();
           DoubleAnimation fadeInAnimation = new DoubleAnimation();
           fadeInAnimation.From = 340;
           fadeInAnimation.To = 0;
           fadeInAnimation.Duration = new Duration(TimeSpan.FromSeconds(1.0));
           Storyboard.SetTarget(fadeInAnimation, r);
           Storyboard.SetTargetProperty(fadeInAnimation, new PropertyPath("(UIElement.RenderTransform).(CompositeTransform.TranslateX)"));
           sb.Children.Add(fadeInAnimation);
           sb.Begin();


it was raising error at sb.begin();

解决方案

Please try this code


// Create a red rectangle that will be the target
// of the animation.
Rectangle myRectangle = new Rectangle();
myRectangle.Width = 200;
myRectangle.Height = 200;
Windows.UI.Color myColor = Windows.UI.ColorHelper.FromArgb(255, 255, 0, 0);
SolidColorBrush myBrush = new SolidColorBrush();
myBrush.Color = myColor;
myRectangle.Fill = myBrush;

// Create the transform
TranslateTransform moveTransform = new TranslateTransform();
moveTransform.X = 0;
moveTransform.Y = 0;
myRectangle.RenderTransform = moveTransform;


// Add the rectangle to the tree.
LayoutRoot.Children.Add(myRectangle);
// Create a duration of 2 seconds.
Duration duration = new Duration(TimeSpan.FromSeconds(1.0));
// Create two DoubleAnimations and set their properties.
DoubleAnimation myDoubleAnimationX = new DoubleAnimation();
Storyboard sb = new Storyboard();
sb.Duration = duration;
sb.Children.Add(myDoubleAnimationX);
Storyboard.SetTarget(myDoubleAnimationX, moveTransform);
Storyboard.SetTargetProperty(myDoubleAnimationX, "X");

myDoubleAnimationX.To = 0;
myDoubleAnimationX.From = 340;

// Make the Storyboard a resource.
LayoutRoot.Resources.Add("unique_id", sb);

// Begin the animation.
sb.Begin();


Thanks,
Bilaal


这篇关于通过c#windows phone创建动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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