简体   繁体   English

RenderTransform WPF /代码背后

[英]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. 我的视图中有一个图像,当发生特殊事件时,我想将图像旋转45度。 But I keep getting this error all the time: 但是我一直都在收到这个错误:

Cannot resolve all property references in the property path 'RenderTransform.Angle' 无法解析属性路径“ 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. RenderTransform没有Angle属性。 Make sure there is a RotationTransformation assigned to the RenderTranformation property of the element you are rotating. 确保已为要旋转的元素的RenderTranformation属性分配了RotationTransformation。

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): 如果将Rotation添加到TransformGroup,则PropertyPath将是(假设Rotation是该组的第一个子级):

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: 您必须将RotateTransform分配给图像的RenderTransform才能使Storyboard正常工作,例如:

<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: 尽管您可以使用Storyboard为其设置动画,但直接在RotateTransform对象上启动动画可能会更容易:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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