wpf 窗体内容旋转效果 网摘

本文介绍了一种使用WPF框架创建按钮控制的矩形旋转动画的方法。通过点击按钮触发旋转动画,利用`RotateTransform`和`DoubleAnimation`实现无限循环的360度旋转效果。

<Window x:Class="simplewpf.chuangtixuanzzhuan"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="chuangtixuanzzhuan" Height="300" Width="300">
    <Grid Name="rectangle2">
        <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="29,67,0,0" Name="button2" VerticalAlignment="Top" Width="75" Click="button2_Click" Canvas.Left="21" Canvas.Top="0" />
        <Rectangle Height="71" HorizontalAlignment="Left" Margin="50,207,0,0"  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"  Canvas.Left="79" Canvas.Top="32" />
    </Grid>
</Window>

 

 

 

//后台代码

     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(3)));
            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();
        }
      //  using System.Windows.Media.Animation;
        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(3)));
            dbAscending.RepeatBehavior = RepeatBehavior.Forever;
            rtf.BeginAnimation(RotateTransform.AngleProperty, dbAscending);
        }

转载于:https://www.cnblogs.com/tianyiwuying/p/3264393.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值