<ControlTemplate TargetType="{x:Type Button}"> <Border x:Name="btn_border" Background="{TemplateBinding Background}" > <TextBlock x:Name="btn_text" Opacity="0" RenderTransformOrigin="0.5,0.5" Text="{TemplateBinding Content}" FontSize="18" FontFamily="Candara" Foreground="Red" FontWeight="Normal" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0 5 0 0" > <TextBlock.RenderTransform> <RotateTransform></RotateTransform> </TextBlock.RenderTransform> </TextBlock> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Cursor" Value="Hand" TargetName="btn_border" /> <Setter Property="Opacity" Value="1" TargetName="btn_text"> </Setter> </Trigger> <EventTrigger RoutedEvent="Button.MouseEnter"> <EventTrigger.Actions> <BeginStoryboard> <Storyboard > <DoubleAnimation Storyboard.TargetName="btn_text" Storyboard.TargetProperty="RenderTransform.Angle" BeginTime="00:00:00" From="0" To="5" Duration="00:00:0.1" AutoReverse="True" RepeatBehavior="Forever" /> </Storyboard> </BeginStoryboard> </EventTrigger.Actions> </EventTrigger> <EventTrigger RoutedEvent="Button.MouseLeave"> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetName="btn_text" Storyboard.TargetProperty="RenderTransform.Angle" BeginTime="00:00:00" From="0" To="0" Duration="00:00:0.1" AutoReverse="True"/> </Storyboard> </BeginStoryboard> </EventTrigger> </ControlTemplate.Triggers> </ControlTemplate>
关键在与在需要变换的元素内声明 元素中心 RenderTransformOrigin(0.5,0.5)
<XX.RenderTransform>
<RotateTransform></RotateTransform>
</XX.RenderTransform>
然后在<Template.Tragers>中定义路由事件控制,定义故事板,触发
时间: 2024-10-07 14:53:59