我想用 C# 代码旋转 XAML 中创建的多边形,但是我被困在 Propertypath 上。有人知道我应该用什么来代替吗?
这是我现在拥有的 C# 代码:
public void Rotate()
{
Storyboard rotate = new Storyboard();
DoubleAnimation myDoubleAnimation = new DoubleAnimation();
myDoubleAnimation.From = 0;
myDoubleAnimation.To = 360;
myDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(5));
Storyboard.SetTargetProperty(myDoubleAnimation, new PropertyPath("(Polygon.RenderTransform).(RotateTransform.Angle)"));
Storyboard.SetTargetName(myDoubleAnimation, Arrowhead.Name);
rotate.Children.Add(myDoubleAnimation);
rotate.Begin(Arrowhead);
}
这是我想在 XAML 中旋转的多边形(三角形):
<Polygon Fill="#41b1ff"
Stroke="Gray"
StrokeThickness="2"
Points="80,60,100,40,100,40,120,60"
Grid.ColumnSpan="3"
Grid.RowSpan="3"
Name="Arrowhead"
/>
最佳答案
您的代码似乎工作正常。您需要添加您要修改的转换:
<Polygon
Fill="#41b1ff"
Stroke="Gray"
StrokeThickness="2"
Points="80,60,100,40,100,40,120,60"
Name="Arrowhead">
<Polygon.RenderTransform>
<RotateTransform/>
</Polygon.RenderTransform>
</Polygon>
关于c# - 从代码旋转对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30374627/