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.
Margin
property can be animated usingThicknessAnimation
Actually, ya you can do what you want to do, exactly as you want to do using
RenderTransform
mixed with someDoubleAnimation
and even add some extra flair to it, for example;Will move that object 50px on the X axis and even fade it in while it does so. Give it a shot and play with the values of the
X
property and theKeyTime
to get what you want. Hope this helps, cheers.You can't animate Margin.Left (because
Left
is not a dependency property), but you can animateMargin
. UseObjectAnimationUsingKeyFrames
:There are some alternatives that allow you to use a
DoubleAnimation
, rather than key frames:Canvas.Left
.TranslateTransform
to your target, and animate its x position usingTranslateTransform.X
.As an alternative answer
@McGarnagle
you can use animation forHorizontalAlignment
andVerticalAlignment
properties.Example: