Dev Drone Bhowmik
Dev Drone Bhowmik

Reputation: 21

Change position of Grid using animation C#

WPF

<Grid Name="GhostGrid">
    <Image Source="img.jpg"/>
</Grid>

I am trying to change the position of a grid using animation. This is working fine -

C#

TranslateTransform transformImage = new TranslateTransform();
GhostGrid.RenderTransform = transformImage;
DoubleAnimation animationImage = new DoubleAnimation(0, -50, TimeSpan.FromSeconds(0.6));
transformImage.BeginAnimation(TranslateTransform.XProperty, animationImage); 

But this not working - C#

DoubleAnimation animationImage = new DoubleAnimation()
{
     From = 0,
     To = -450,
     Duration = new Duration(TimeSpan.FromSeconds(0.8))
};
Storyboard.SetTarget(animationImage, GhostGrid);
Storyboard.SetTargetProperty(animationImage,new PropertyPath(TranslateTransform.XProperty));
storyBoard = new Storyboard();
storyBoard.Children.Add(animationImage);
storyBoard.Begin();

Upvotes: 1

Views: 63

Answers (1)

Dev Drone Bhowmik
Dev Drone Bhowmik

Reputation: 21

As per Clemens suggestion its working now -

DoubleAnimation animationImage = new DoubleAnimation()
{
     From = 0,
     To = -450,
     Duration = new Duration(TimeSpan.FromSeconds(0.8))
};
Storyboard.SetTarget(animationImage, GhostGrid);
Storyboard.SetTargetProperty(animationImage,new PropertyPath("RenderTransform.X"));
storyBoard = new Storyboard();
storyBoard.Children.Add(animationImage);
storyBoard.Begin();

Upvotes: 1

Related Questions