WPF 按键图标转动效果示例

html 复制代码
        <Storyboard x:Key="IconStoryboard">
            <DoubleAnimation
                                Storyboard.TargetName="PackIconFileIcon"
                                Storyboard.TargetProperty="(iconPacks:PackIconFileIcons.RotationAngle)"
                                From="0"
                                To="360"
                                Duration="0:0:0.3"
                               />
        </Storyboard>

        <ToggleButton x:Name="toggleBtn" VerticalAlignment="Top" Width="30" Height="30" Margin="0,0,0,0">
            <iconPacks:PackIconFileIcons x:Name="PackIconFileIcon" Kind="Actionscript"  />
        </ToggleButton>
csharp 复制代码
		private void toggleBtn_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
		{
			_pressedPosition2 = e.GetPosition(this);
		}

		private void toggleBtn_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
		{
			if (Mouse.LeftButton == MouseButtonState.Released && _pressedPosition2 == e.GetPosition(this))
			{
				if (toggleBtn.IsChecked == true)
				{
					//ItemsCtrl.Visibility = Visibility.Visible;
					var expandStoryboard = (Storyboard)FindResource("ExpandStoryboard");
					expandStoryboard.Begin();

					var IconStoryboard = (Storyboard)FindResource("IconStoryboard");
					IconStoryboard.Begin();
				}
				else
				{
					var collapseStoryboard = (Storyboard)FindResource("CollapseStoryboard");
					collapseStoryboard.Begin();

					var IconStoryboard = (Storyboard)FindResource("IconStoryboard");
					IconStoryboard.Begin();
					//ItemsCtrl.Visibility = Visibility.Hidden;
				}
			}
		}
相关推荐
湫ccc40 分钟前
《Python基础》之字符串格式化输出
开发语言·python
mqiqe1 小时前
Python MySQL通过Binlog 获取变更记录 恢复数据
开发语言·python·mysql
AttackingLin1 小时前
2024强网杯--babyheap house of apple2解法
linux·开发语言·python
Ysjt | 深2 小时前
C++多线程编程入门教程(优质版)
java·开发语言·jvm·c++
ephemerals__2 小时前
【c++丨STL】list模拟实现(附源码)
开发语言·c++·list
码农飞飞2 小时前
深入理解Rust的模式匹配
开发语言·后端·rust·模式匹配·解构·结构体和枚举
一个小坑货2 小时前
Rust 的简介
开发语言·后端·rust
湫ccc2 小时前
《Python基础》之基本数据类型
开发语言·python