<Style x:Key="MoveButton" TargetType="Button">
<Setter Property="Foreground" Value="White"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Canvas x:Name="gd" >
<Border x:Name="back" Background="{TemplateBinding Background}" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}">
<ContentPresenter x:Name="cp" Content="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center" IsHitTestVisible="False"/>
</Border>
</Canvas>
<ControlTemplate.Triggers>
<Trigger Property="IsPressed" Value="true">
<!--样式动画,EnterActions活动状态,ExitActions非活动状态-->
<Trigger.EnterActions>
<!--BeginStoryboard 触发器操作,该操作可启动Storyboard -->
<BeginStoryboard>
<!--Storyboard一个容器时间线,该时间线为子动画提供对象和属性确定信息-->
<Storyboard>
<!--Double属性值进行动画处理DoubleAnimation-->
<DoubleAnimation From="0" To="2" Duration="0:0:0.1" Storyboard.TargetName="back" Storyboard.TargetProperty="(Canvas.Top)" />
<DoubleAnimation From="0" To="1" Duration="0:0:0.1" Storyboard.TargetName="back" Storyboard.TargetProperty="(Canvas.Left)" />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation From="2" To="0" Duration="0:0:0.1" Storyboard.TargetName="back" Storyboard.TargetProperty="(Canvas.Top)" />
<DoubleAnimation From="1" To="0" Duration="0:0:0.1" Storyboard.TargetName="back" Storyboard.TargetProperty="(Canvas.Left)" />
</Storyboard>
</BeginStoryboard>
</Trigger.ExitActions>
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Foreground" Value="Red" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
WPF之弹动Button
最新推荐文章于 2023-12-28 21:11:40 发布