日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

代码创建 WPF 旋转动画

發布時間:2025/3/18 asp.net 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 代码创建 WPF 旋转动画 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
原文:代碼創建 WPF 旋轉動畫

版權聲明:本文為博主原創文章,未經博主允許不得轉載。 https://blog.csdn.net/a771948524/article/details/9304001

一、WPF窗體上有一個名為rectangle2的矩形

對應的XAML如下:

<Window x:Class="WpfVideo.Window1"
??????? xmlns="
http://schemas.microsoft.com/winfx/2006/xaml/presentation"
??????? xmlns:x="
http://schemas.microsoft.com/winfx/2006/xaml"
??????? Title="Window1" Height="434" Width="593" Loaded="Window_Loaded">
??? <Grid>
??????? <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="29,67,0,0" Name="button2" VerticalAlignment="Top" Width="75" Click="button2_Click" />
<Rectangle Height="71" HorizontalAlignment="Left" Margin="50,207,0,0" Name="rectangle2" Stroke="Black" VerticalAlignment="Top" Width="101" Fill="#FF967878" />
??????? <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="162,67,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
??? </Grid>
< /Window>

二、方法一

private void button1_Click(object sender, RoutedEventArgs e)
??????? {
??????????? RotateTransform rtf = new RotateTransform();
??????????? rectangle2.RenderTransform = rtf;
??????????? DoubleAnimation dbAscending = new DoubleAnimation(0, 360, new Duration(TimeSpan.FromSeconds(1)));
??????????? Storyboard storyboard = new Storyboard();
??????????? dbAscending.RepeatBehavior = RepeatBehavior.Forever;
??????????? storyboard.Children.Add(dbAscending);
??????????? Storyboard.SetTarget(dbAscending, rectangle2);
??????????? Storyboard.SetTargetProperty(dbAscending, new PropertyPath("RenderTransform.Angle"));
??????????? storyboard.Begin();
??????? }

三、方法二

private void button2_Click(object sender, RoutedEventArgs e)
??????? {
??????????? RotateTransform rtf = new RotateTransform();
??????????? rectangle2.RenderTransform = rtf;
??????????? DoubleAnimation dbAscending = new DoubleAnimation(0, 360, new Duration(TimeSpan.FromSeconds(1)));
??????????? dbAscending.RepeatBehavior = RepeatBehavior.Forever;
??????????? rtf.BeginAnimation(RotateTransform.AngleProperty, dbAscending);
??????? }

總結

以上是生活随笔為你收集整理的代码创建 WPF 旋转动画的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。