简体   繁体   中英

Rendertransform wpf/code behind

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();

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)"

You would have to assign a RotateTransform to your Image's RenderTransform to make your Storyboard work, eg 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM