WPF中的转换有:
// 在二维 x-y 坐标系内围绕指定点按顺时针方向旋转对象。 <RotateTransform /> // 在二维 x-y 坐标系中平移(移动)对象。 <TranslateTransform /> // 在 2-D x-y 坐标系统内缩放对象。 <ScaleTransform /> // 表示 2-D 倾斜。 <SkewTransform />
将转换与关键帧动画共用:
<Button x:Name="Button01" Grid.Row="1" Grid.Column="2" Width="100" Content="Click Me" RenderTransformOrigin="0,0"> <Button.RenderTransform> <TransformGroup> <RotateTransform /> <TranslateTransform /> <ScaleTransform /> <SkewTransform /> </TransformGroup> </Button.RenderTransform> <Button.Triggers> <EventTrigger RoutedEvent="MouseEnter"> <EventTrigger.Actions> <BeginStoryboard> <Storyboard> <DoubleAnimationUsingKeyFrames AutoReverse="False" BeginTime="0:0:0.0" Storyboard.TargetName="Button01" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(ScaleTransform.ScaleX)"> <EasingDoubleKeyFrame KeyTime="0:0:0.0" Value="1" /> <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0.5" /> </DoubleAnimationUsingKeyFrames> </Storyboard> </BeginStoryboard> </EventTrigger.Actions> </EventTrigger> <EventTrigger RoutedEvent="MouseLeave"> <BeginStoryboard> <Storyboard> <DoubleAnimationUsingKeyFrames AutoReverse="False" Storyboard.TargetName="Button01" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(ScaleTransform.ScaleX)"> <EasingDoubleKeyFrame KeyTime="0:0:0" Value="0.5" /> <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="1" /> </DoubleAnimationUsingKeyFrames> </Storyboard> </BeginStoryboard> </EventTrigger> </Button.Triggers> </Button>
如果xaml中,去掉以下代码:
<Button.RenderTransform> <TransformGroup> <RotateTransform /> <TranslateTransform /> <ScaleTransform /> <SkewTransform /> </TransformGroup> </Button.RenderTransform>
代码可以编译成功,运行便会报错,错误信息如下:
代码中的:TransformGroup是一个类,该类中封装着一个属性Children,Children是一个TransformCollection类型,就是一个集合,该集合中的元素,如下:
TransformCollection[0] = RotateTransform实例 TransformCollection[1] = TranslateTransform TransformCollection[2] = ScaleTransform TransformCollection[3] = SkewTransform
所以,关键帧动画中的TargetProperty属性值 ,取集合中的第三个:Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(ScaleTransform.ScaleX)"
本例中,只用到ScaleTransform缩放功能,也可以写成下面样式
<Button.RenderTransform> <TransformGroup> <ScaleTransform /> </TransformGroup> </Button.RenderTransform>
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)"
标签:动画,关键帧,ScaleTransform,TransformCollection,WPF,Children,属性 From: https://www.cnblogs.com/OctopusKing/p/17114842.html