zoukankan      html  css  js  c++  java
  • 代码创建 WPF 旋转动画

    一、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);
            }

  • 相关阅读:
    【iOS】7.4 定位服务->2.1.1 定位
    【iOS】7.4 定位服务->1.0 简介
    1.2.1 OC概述
    5.1 网络基础
    4.4 多线程进阶篇<下>(NSOperation)
    4.3 多线程进阶篇<中>(GCD)
    4.1/4.2 多线程进阶篇<上>(Pthread & NSThread)
    4.0 多线程基础篇
    2.1 -1.0 Xcode(发布时间、使用、快捷键、插件相关)
    一款面试复习应用源码
  • 原文地址:https://www.cnblogs.com/jiangu66/p/3187194.html
Copyright © 2011-2022 走看看