Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to animate Margin property in WPF

I want to move animate an rectangle object to move it in x-axis. I am new to WPF animation, started out with the following:

<Storyboard x:Key="MoveMe">     <DoubleAnimationUsingKeyFrames BeginTime="00:00:00"                                     Storyboard.TargetName="GroupTileSecond"                                    Storyboard.TargetProperty="(**Margin.Left**)">          <SplineDoubleKeyFrame KeyTime="00:00:00" Value="**134, 70,0,0**" />         <SplineDoubleKeyFrame KeyTime="00:00:03" Value="**50, 70,0,0**" />     </DoubleAnimationUsingKeyFrames> </Storyboard> 

Obviously found out that I cant use Margin.Left as Storyboard.TargetProperty or use 134,70,0,0 in Value property.

So, how do I move an object in XAML WPF.

like image 692
Gaja Kannan Avatar asked Feb 04 '14 03:02

Gaja Kannan


1 Answers

Margin property can be animated using ThicknessAnimation

<Storyboard >      <ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="Margin" BeginTime="00:00:00">         <SplineThicknessKeyFrame KeyTime="00:00:00" Value="134, 70,0,0" />         <SplineThicknessKeyFrame KeyTime="00:00:03" Value="50, 70,0,0" />      </ThicknessAnimationUsingKeyFrames> </Storyboard> 
like image 102
Mat J Avatar answered Sep 22 '22 05:09

Mat J