【问题标题】:Path Animation into a Button路径动画到按钮
【发布时间】:2016-11-07 20:38:51
【问题描述】:

我有一个带路径的按钮,我想要的是当我点击按钮时,路径会移动到右侧;我已将样式和触发器添加到按钮,但它不起作用。我试图将触发器添加到 ControlTemplate 但它不允许我

如果您有任何建议,我将不胜感激。

这是我的代码:

<Button x:Name="btnEnviarCorreo" Height="50" Width="100" Padding="5"  Content="Enviar Correo" Margin="2,2" >
<Button.Style>
<Style TargetType="Button">
<Setter Property="Background" Value="SteelBlue"/>
<Setter Property="Foreground" Value="White" />
<Setter Property="FontSize" Value="15" />
<Setter Property="FontFamily" Value="./#Segoe UI" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border CornerRadius="4" Background="{TemplateBinding Background}">
<Grid>
<Path x:Name="PathIcon" Width="15" Height="25" Stretch="Fill" Fill="#E59400" HorizontalAlignment="Left" Margin="17,0,0,0" Data="F1M30.0833,22.1667L50.6665,37.6043 50.6665,38.7918 30.0833,53.8333 30.0833,22.1667z"/>                                                          <ContentPresenter x:Name="MyContentPresenter" Content="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,0,0" />
</Grid>                                 
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#E59400" />
<Setter Property="Foreground" Value="White" />
<Setter TargetName="PathIcon" Property="Fill" Value="Black" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" Value="OrangeRed" />
<Setter Property="Foreground" Value="White" />
</Trigger>                                  
</ControlTemplate.Triggers>                             
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<EventTrigger RoutedEvent="Click">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="PathIcon" Storyboard.TargetProperty="RenderTransform.(TranslateTransform.X)" From="0" To="200" />
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Style.Triggers>
</Style>                
</Button.Style>
</Button>

感谢您的宝贵时间。

【问题讨论】:

    标签: wpf animation events button path


    【解决方案1】:

    ControlTemplate.Triggers 块内的某处添加以下代码:

    <EventTrigger RoutedEvent="MouseEnter">
                                        <BeginStoryboard>
                                            <Storyboard>
                                                <ThicknessAnimation From="17,0,0,0" To="100, 0, 0, 0" Duration="0:0:1" Storyboard.TargetProperty="Margin"
                                                                    Storyboard.TargetName="PathIcon"/> 
                                            </Storyboard>
                                        </BeginStoryboard>
                                    </EventTrigger>
    

    这并不完美,您应该自己设置一些细节。我在EventTrigger 中为 Margin 使用动画。你可以尝试做一些其他的实验:D

    【讨论】:

    • 非常感谢,这对我帮助很大。非常感谢您的帮助
    猜你喜欢
    • 2021-12-19
    • 2017-03-22
    • 2022-01-03
    • 2010-12-25
    • 1970-01-01
    • 2020-04-20
    • 2016-02-14
    • 2016-01-06
    • 1970-01-01
    相关资源
    最近更新 更多