Unicorn
Unicorn

Reputation: 21

How to animate an attached property?

I have a label in canvas. I want to animate the Canvas.Left of the label, but I don't known how to do it...

 DoubleAnimation Label_dx = new DoubleAnimation(150,60, new Duration(new TimeSpan(0, 0, 1)));

 label.BeginAnimation(???, Label_dx);

Upvotes: 2

Views: 158

Answers (2)

Ouadie
Ouadie

Reputation: 13185

you can also use :

label.BeginAnimation(Canvas.LeftProperty, Label_dx);

or

TranslateTransform trans = new TranslateTransform();
label.RenderTransform = trans;
DoubleAnimation anim = new DoubleAnimation(150,60, new Duration(new TimeSpan(0, 0, 1));
trans.BeginAnimation(TranslateTransform.YProperty, anim);

The TranslateTransform is a specific kind of render transformation. Rather that changing properties of the control (such as the Left property), it simply affects how the control is displayed on the screen

Upvotes: 2

max
max

Reputation: 34407

Try

label.BeginAnimation(Canvas.LeftProperty, Label_dx);

Upvotes: 2

Related Questions