WPF 按键图标缩放动画示例

html 复制代码
	
    <mah:MetroWindow.Resources>
        <Storyboard x:Key="ExpandStoryboard">
            <DoubleAnimation
                                Storyboard.TargetName="CtrlGrid"
                                Storyboard.TargetProperty="Width"
                                From="0"
                                To="100"
                                Duration="0:0:0.2"
                                />
        </Storyboard>

        <Storyboard x:Key="CollapseStoryboard">
            <DoubleAnimation
                                Storyboard.TargetName="CtrlGrid"
                                Storyboard.TargetProperty="Width"
                                From="100"
                                To="0"
                                Duration="0:0:0.2"
                                 />
        </Storyboard>

        <Storyboard x:Key="IconStoryboard">
            <DoubleAnimation
                                Storyboard.TargetName="PackIconFileIcon"
                                Storyboard.TargetProperty="(iconPacks:PackIconFileIcons.RotationAngle)"
                                From="0"
                                To="360"
                                Duration="0:0:0.3"
                               />
        </Storyboard>
    </mah:MetroWindow.Resources>

 <ToggleButton x:Name="toggleBtn" VerticalAlignment="Top" Width="30" Height="30" Margin="0,0,0,0">
            <iconPacks:PackIconVaadinIcons Kind="DotCircle" x:Name="PackIconFileIcon" Foreground="#FF6AFCFF" >
                <iconPacks:PackIconVaadinIcons.RenderTransformOrigin>
                    <Point X="0.5" Y="0.5"/>
                </iconPacks:PackIconVaadinIcons.RenderTransformOrigin>
                <iconPacks:PackIconVaadinIcons.RenderTransform>
                    <ScaleTransform ScaleX="1" ScaleY="1" x:Name="iconScaleTransform" />
                </iconPacks:PackIconVaadinIcons.RenderTransform>
            </iconPacks:PackIconVaadinIcons>
            <ToggleButton.Triggers>
                <EventTrigger RoutedEvent="ToggleButton.Checked">
                    <BeginStoryboard>
                        <Storyboard>
                            <ColorAnimation Storyboard.TargetName="PackIconFileIcon" Storyboard.TargetProperty="(Foreground).(SolidColorBrush.Color)" To="#FF97FFBA" Duration="0:0:0" />
    
                            <!--<DoubleAnimationUsingKeyFrames Storyboard.TargetName="iconScaleTransform" Storyboard.TargetProperty="(ScaleTransform.ScaleX)">
                                <EasingDoubleKeyFrame KeyTime="0:0:0" Value="1" />
                                <EasingDoubleKeyFrame KeyTime="0:0:0.25" Value="1.5" />
                                <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="1" />
                            </DoubleAnimationUsingKeyFrames>
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="iconScaleTransform" Storyboard.TargetProperty="(ScaleTransform.ScaleY)">
                                <EasingDoubleKeyFrame KeyTime="0:0:0" Value="1" />
                                <EasingDoubleKeyFrame KeyTime="0:0:0.25" Value="1.5" />
                                <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="1" />
                            </DoubleAnimationUsingKeyFrames>-->
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
                <EventTrigger RoutedEvent="ToggleButton.Unchecked">
                    <BeginStoryboard>
                        <Storyboard>
                            <ColorAnimation Storyboard.TargetName="PackIconFileIcon" Storyboard.TargetProperty="(Foreground).(SolidColorBrush.Color)" To="#FF6AFCFF" Duration="0:0:0" />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
                
                <EventTrigger RoutedEvent="UIElement.MouseEnter">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation To="1.5" Duration="0:0:0.25" Storyboard.TargetName="iconScaleTransform" Storyboard.TargetProperty="(ScaleTransform.ScaleX)"/>
                            <DoubleAnimation To="1.5" Duration="0:0:0.25" Storyboard.TargetName="iconScaleTransform" Storyboard.TargetProperty="(ScaleTransform.ScaleY)"/>
                        
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>

                <EventTrigger RoutedEvent="UIElement.MouseLeave">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation To="1" Duration="0:0:0.25" Storyboard.TargetName="iconScaleTransform" Storyboard.TargetProperty="(ScaleTransform.ScaleX)"/>
                            <DoubleAnimation To="1" Duration="0:0:0.25" Storyboard.TargetName="iconScaleTransform" Storyboard.TargetProperty="(ScaleTransform.ScaleY)"/>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </ToggleButton.Triggers>
        </ToggleButton>
相关推荐
FuckPatience1 小时前
C# 实现元素索引由1开始的链表
开发语言·链表·c#
我是唐青枫5 小时前
C#.NET 范围与索引(Range、Index)完全解析:语法、用法与最佳实践
c#·.net
烛阴7 小时前
从`new()`到`.DoSomething()`:一篇讲透C#方法与构造函数的终极指南
前端·c#
深海潜水员7 小时前
【MonoGame游戏开发】| 牧场物语实现 第一卷 : 农场基础实现 (下)
vscode·游戏·c#·.net·monogame
合作小小程序员小小店8 小时前
图书管理系统,基于winform+sql sever,开发语言c#,数据库mysql
开发语言·数据库·sql·microsoft·c#
大侠课堂19 小时前
C#经典面试题100道
开发语言·c#
时光追逐者20 小时前
Visual Studio 2026 现已正式发布,更快、更智能!
ide·c#·.net·visual studio
周杰伦fans1 天前
C# 正则表达式完全指南
mysql·正则表达式·c#
Triumph++1 天前
电器模C#汇控电子继块驱动(Modbus协议)
c#·visual studio·c#串口通信
咩图1 天前
C#创建AI项目
开发语言·人工智能·c#