uwp 中的动画

xml

---------------------------------------

<Page

    x:Class="MyApp.MainPage"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:local="using:MyApp"

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d"

    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

 

    <Grid>

        <Path HorizontalAlignment="Center" VerticalAlignment="Center" Width="300" Height="300" Stretch="Uniform" Fill="Yellow" RenderTransformOrigin="0.5,0.5">

            <Path.Data>

                <GeometryGroup>

                    <EllipseGeometry Center="50,50" RadiusX="50" RadiusY="20"/>

                    <EllipseGeometry Center="50,50" RadiusX="20" RadiusY="50"/>

                </GeometryGroup>

            </Path.Data>

            <Path.RenderTransform>

                <RotateTransform x:Name="rttrf" Angle="0"/>

            </Path.RenderTransform>

        </Path>

    </Grid>

</Page>

 

 

C# code

-------------------------------------------

  public sealed partial class MainPage : Page

    {

        Storyboard m_storyboard = null;

        public MainPage()

        {

            this.InitializeComponent();

 

            this.NavigationCacheMode = NavigationCacheMode.Required;

 

            // 初始化演示图板

            m_storyboard = new Storyboard();

            // 定义时间线

            DoubleAnimation da = new DoubleAnimation();

            da.Duration = TimeSpan.FromSeconds(2d); //时间线持续时间

            da.From = 0d; //初始值

            da.To = 360d; //最终值

            // 设置为无限循环播放

            da.RepeatBehavior = RepeatBehavior.Forever;

            // 将时间线与RotateTransform对象关联

            Storyboard.SetTarget(da, rttrf);

            Storyboard.SetTargetProperty(da, "Angle");

            // 将时间线加入Storyboard的时间线集合中

            m_storyboard.Children.Add(da);

        }

 

        protected override void OnNavigatedTo(NavigationEventArgs e)

        {

            // 开始播放动画

            m_storyboard.Begin();

        }

    }

 

 

 

 

 

posted @ 2021-01-02 12:08  MaxBruce  阅读(90)  评论(0编辑  收藏  举报