1 回答
TA贡献1806条经验 获得超5个赞
如果将该RenderTransform属性设置为 a ScaleTransform,则实际上会删除RotateTransform,反之亦然。
为了能够同时应用两种转换,您可以使用TransformGroup:
<Grid x:Name="grid1" Grid.Row="0">
<Image x:Name="image1" Source="Images/Buldingimage.jpeg"/>
<Grid.RenderTransform>
<TransformGroup>
<RotateTransform x:Name="rt" />
<ScaleTransform x:Name="st" />
</TransformGroup>
</Grid.RenderTransform>
</Grid>
然后,您只需像以前一样更改Angle和RotateTransform动画ScaleTransform:
double rotationAngle = 0;
private void Button_Click_1(object sender, RoutedEventArgs e)
{
//Rotate
this.rotationAngle += 90;
this.grid1.RenderTransformOrigin = new Point(0.5, 0.5);
rt.Angle = this.rotationAngle;
}
bool mIsHorizontalImageflipped = false;
private void Button_Click_2(object sender, RoutedEventArgs e)
{
//Transform
int[] value;
float[] origin = new float[] { 0.5f, 0.5f };
string path = "RenderTransform.Children[1].ScaleX";
if (!this.mIsHorizontalImageflipped)
{
value = new int[] { 1, -1 };
this.mIsHorizontalImageflipped = true;
}
else
{
this.mIsHorizontalImageflipped = false;
value = new int[] { -1, 1 };
}
this.Animate(value, origin, path);
}
internal void Animate(int[] value, float[] origin, string path)
{
Storyboard sb = new Storyboard();
this.grid1.RenderTransformOrigin = new Point(origin[0], origin[1]);
DoubleAnimationUsingKeyFrames keyFrames = new DoubleAnimationUsingKeyFrames();
SplineDoubleKeyFrame keyFrame = new SplineDoubleKeyFrame();
keyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0));
keyFrame.Value = value[0];
keyFrames.KeyFrames.Add(keyFrame);
keyFrame = new SplineDoubleKeyFrame();
keyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1));
KeySpline keySpline = new KeySpline();
keySpline.ControlPoint1 = new Point(0.64, 0.84);
keySpline.ControlPoint2 = new Point(0, 1);
keyFrame.KeySpline = keySpline;
keyFrames.KeyFrames.Add(keyFrame);
keyFrame.Value = value[1];
Storyboard.SetTargetProperty(keyFrames, new PropertyPath(path));
Storyboard.SetTarget(keyFrames, this.grid1);
sb.Children.Add(keyFrames);
sb.Begin();
}
- 1 回答
- 0 关注
- 209 浏览
添加回答
举报