Tobias Moe Thorstensen
Tobias Moe Thorstensen

Reputation: 8981

Where to assign RenderTransform on animated image

I have a image in my View, which I want to rotate my image 45 degress when a special event happens. But I keep getting this error all the time:

Cannot resolve all property references in the property path 'RenderTransform.Angle'

What type of property path do I need to set to accomplish this?

var dbAscending = new DoubleAnimation(0, 45, new Duration(TimeSpan.FromMilliseconds(1000)));
var storyboard = new Storyboard();
storyboard.Children.Add(dbAscending);
Storyboard.SetTarget(dbAscending, uc.Cross);
Storyboard.SetTargetProperty(dbAscending, new PropertyPath("RenderTransform.Angle"));
storyboard.Begin();

Upvotes: 0

Views: 6366

Answers (2)

Emond
Emond

Reputation: 50712

A RenderTransform has no Angle property. Make sure there is a RotationTransformation assigned to the RenderTranformation property of the element you are rotating.

new PropertyPath("(UIElement.RenderTransform).(RotateTransform.Angle)"

If you added the Rotation to a TransformGroup the PropertyPath would be (assuming the Rotation is the first child of the group):

new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(RotateTransform.Angle)"

Upvotes: 2

Clemens
Clemens

Reputation: 128157

You would have to assign a RotateTransform to your Image's RenderTransform to make your Storyboard work, e.g. like this:

<Image RenderTransformOrigin="0.5,0.5" ...>
    <Image.RenderTransform>
        <RotateTransform x:Name="imageRotation"/>
    </Image.RenderTransform>
</Image>

Although you could animate this with your Storyboard, it might be easier to just start the animation directly on the RotateTransform object:

var rotationAnimation = new DoubleAnimation(45, TimeSpan.FromSeconds(1));
imageRotation.BeginAnimation(RotateTransform.AngleProperty, rotationAnimation);

Upvotes: 2

Related Questions