TransformGroup:能够让某对象的缩放、旋转、扭曲等变化效果合并起来使用。
<Window x:Class="WpfApplication1.xly"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="xly" Height="300" Width="800">
<Window.Resources>
<!--按钮样式-->
<Style TargetType="{x:Type Image}">
<!--RenderTransformOrigin 改变按钮里面的变形 RenderTransform按钮变形属性-->
<Setter Property="RenderTransformOrigin" Value="0.5,0.5"/>
<Setter Property="RenderTransform">
<Setter.Value>
<!--使用RenderTransform时,要使用TransformGroup,否则不能动-->
<TransformGroup>
<!--多种变形,其中一种RotateTransform旋转-->
<RotateTransform/>
</TransformGroup>
</Setter.Value>
</Setter>
<!--样式触发器-->
<Style.Triggers>
<!--按钮的MouseEnter鼠标进入事件-->
<EventTrigger RoutedEvent="Button.MouseEnter">
<EventTrigger.Actions>
<BeginStoryboard>
<!--动画,操控RotateTransform变形 Angle角度 从0度 From="0" 变成360度 To="360"-->
<Storyboard RepeatBehavior="Forever" Storyboard.TargetProperty="RenderTransform.Children[0].Angle">
<DoubleAnimation From="0" RepeatBehavior="Forever" To="360" Duration="0:0:2"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
<!-- MouseLeave 鼠标离开事件-->
<EventTrigger RoutedEvent="Button.MouseLeave">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard Storyboard.TargetProperty="RenderTransform.Children[0].Angle">
<DoubleAnimation From="0" To="360" RepeatBehavior="Forever" Duration="0:0:10"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid Background="Black">
<Path Stroke="Gray" Fill="#FF858080" Data="M 50,150 Q 200,50 350,150 Q 200,250 50,150" Margin="-10,-10,10,10"></Path>
<Path Stroke="Gray" Fill="#FF858080" Data="M 50,150 Q 200,50 350,150 Q 200,250 50,150" Margin="368.4,-10,-368.4,10"></Path>
<Ellipse Fill="#FFF7AAAA" HorizontalAlignment="Left" Height="100" Margin="135,88,0,0" Stroke="Gray" VerticalAlignment="Top" Width="100"/>
<Ellipse Fill="#FFF7AAAA" HorizontalAlignment="Left" Height="100" Margin="524,88,0,0" Stroke="Gray" VerticalAlignment="Top" Width="100"/>
<!--<Image Source="E:\驾校宝典\Demo\WpfApplication1\lmage\01.PNG" Margin="78,75,494.6,65.4"/>-->
<Image Source="E:\驾校宝典\Demo\WpfApplication1\lmage\image\timg (11).png" Margin="122,102,538.6,87.4"/>
<Image Source="E:\驾校宝典\Demo\WpfApplication1\lmage\image\timg (11).png" Margin="511,102,149.6,87.4"/>
</Grid>
效果截图(红色的眼球会转动)