背水一戰 Windows 10 (14) - 動畫: 線性動畫, 關鍵幀動畫

来源:http://www.cnblogs.com/webabcd/archive/2016/05/26/5529948.html
-Advertisement-
Play Games

[源碼下載] 背水一戰 Windows 10 (14) - 動畫: 線性動畫, 關鍵幀動畫 作者:webabcd介紹背水一戰 Windows 10 之 動畫 線性動畫 - ColorAnimation, DoubleAnimation, PointAnimation 關鍵幀動畫 - ColorAni ...


[源碼下載]


背水一戰 Windows 10 (14) - 動畫: 線性動畫, 關鍵幀動畫



作者:webabcd


介紹
背水一戰 Windows 10 之 動畫

  • 線性動畫 - ColorAnimation, DoubleAnimation, PointAnimation
  • 關鍵幀動畫 - ColorAnimationUsingKeyFrames, DoubleAnimationUsingKeyFrames, PointAnimationUsingKeyFrames, ObjectAnimationUsingKeyFrames



示例
1、演示線性動畫的應用
Animation/LinearAnimation.xaml

<Page
    x:Class="Windows10.Animation.LinearAnimation"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Windows10.Animation"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="Transparent">
        
        <!--
            線性動畫一共有 3 種:ColorAnimation, DoubleAnimation, PointAnimation, 它們均繼承自 Timeline
        
            Storyboard.TargetName - 附加屬性,要進行動畫處理的對象的名稱
            Storyboard.TargetProperty - 附加屬性,要進行動畫處理的對象的屬性
            BeginTime - 時間線在被觸發 BeginTime 的時間後才能開始播放
                TimeSpan - [-][日.]時:分:秒[.1位到7為的秒後的小數](可為正;可為負;可為空;預設值為 0)
            From - 動畫的起始值
            To - 動畫的結束值
            By - 動畫從起始值開始計算,所需變化的總量(To 優先於 By)
            Duration - 時間線的持續時間
                TimeSpan - [-][日.]時:分:秒[.1位到7為的秒後的小數]
                Automatic - 自動確定
                Forever - 無限長
            AutoReverse - 動畫完成後是否要原路返回。預設值為 false
            RepeatBehavior - 動畫重覆播放的時間、次數或類型
                TimeSpan - [-][日.]時:分:秒[.1位到7為的秒後的小數]
                nx - 播放次數。1x, 2x, 3x 
                Forever - 永久播放
            SpeedRatio - 時間線的速率的倍數。預設值 1
            FillBehavior - 動畫結束後的行為(System.Windows.Media.Animation.FillBehavior 枚舉)
                FillBehavior.HoldEnd - 動畫結束後,UI 保留動畫後的狀態。預設值
                FillBehavior.Stop - 動畫結束後,UI 恢復為動畫前的狀態
        
        
            註意:
            1、在 WinRT 中為了流暢的體驗,部分動畫被優化成了“獨立動畫”,即動畫不依賴於 UI 線程
            2、但是也有一部分動畫無法優化成“獨立動畫”,我們把這類動畫稱作“依賴動畫”,其需要在 UI 線程上運行
            3、通過將 EnableDependentAnimation 設置為 true(預設為 false),開啟“依賴動畫”
            4、通過將 Timeline.AllowDependentAnimations 設置為 false(預設為 true),可以全局禁止開啟“依賴動畫”
        
            Independent Animation - 獨立動畫
            Dependent Animation - 依賴動畫
        -->

        <Grid.Resources>
            <BeginStoryboard x:Name="storyboardColor">
                <Storyboard>
                    <!--Color 值線性動畫-->
                    <!--
                        動畫要修改的屬性是 Ellipse.Fill,Fill 是 Brush 類型,先把其轉換為 SolidColorBrush 類型,然後設置 SolidColorBrush 的 Color 屬性
                        所以將 Storyboard.TargetProperty 設置為 (Ellipse.Fill).(SolidColorBrush.Color),也可以設置為 (Fill).(SolidColorBrush.Color),也可以設置為 (Ellipse.Fill).Color,也可以設置為 (Fill).(Color)
                        類似的比如:(UIElement.RenderTransform).(CompositeTransform.TranslateY) 以及 (UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX) 等
                    -->
                    <ColorAnimation
                        Storyboard.TargetName="ellipse" 
                        Storyboard.TargetProperty="(Ellipse.Fill).(SolidColorBrush.Color)" 
                        BeginTime="00:00:00" 
                        From="Red" 
                        To="Yellow" 
                        Duration="0:0:3" 
                        AutoReverse="true" 
                        RepeatBehavior="3x">
                    </ColorAnimation>
                </Storyboard>
            </BeginStoryboard>

            <BeginStoryboard x:Name="storyboardDouble">
                <Storyboard>
                    <!--Double 值線性動畫-->
                    <!--
                        動畫要修改的屬性是 Canvas.Left(附加屬性)
                        將 Storyboard.TargetProperty 設置為 (Canvas.Left)
                    -->
                    <DoubleAnimation
                        Storyboard.TargetName="rectangle" 
                        Storyboard.TargetProperty="(Canvas.Left)"
                        From="100"
                        By="100"
                        BeginTime="0:0:0"
                        Duration="00:00:03"
                        AutoReverse="true"
                        RepeatBehavior="Forever">
                    </DoubleAnimation>
                </Storyboard>
            </BeginStoryboard>

            <Storyboard x:Name="storyboardPoint">
                <!--Point 值線性動畫-->
                <!--
                    動畫要修改的屬性是 Center
                    將 Storyboard.TargetProperty 設置為 Center,也可以將其設置為 (EllipseGeometry.Center)
                -->
                <PointAnimation 
                        EnableDependentAnimation="True"
                        Storyboard.TargetName="ellipseGeometry"
                        Storyboard.TargetProperty="Center"
                        BeginTime="00:00:00"
                        From="50,50"
                        To="200,200"
                        Duration="00:00:03"
                        AutoReverse="true"
                        RepeatBehavior="Forever">
                </PointAnimation>
            </Storyboard>
        </Grid.Resources>

        <StackPanel Margin="10 0 10 10">

            <Ellipse x:Name="ellipse" Fill="Orange" Width="200" Height="100" HorizontalAlignment="Left" />

            <Canvas Width="400" Height="100" HorizontalAlignment="Left" Margin="0 10 0 0">
                <Rectangle x:Name="rectangle" Fill="Orange" Width="200" Height="100" Canvas.Left="100" />
            </Canvas>

            <Path Fill="Orange">
                <Path.Data>
                    <EllipseGeometry x:Name="ellipseGeometry" Center="50,50" RadiusX="15" RadiusY="15" />
                </Path.Data>
            </Path>

            <!--用於演示如何在 CodeBehind 端定義 Storyboard-->
            <Ellipse x:Name="ellipse2" Fill="Orange" Width="200" Height="100" HorizontalAlignment="Left" />

        </StackPanel>
    </Grid>
</Page>

Animation/LinearAnimation.xaml.cs

/*
 * 本例用於演示如何通過 Storyboard 使用線性動畫,線性動畫一共有 3 種類型:ColorAnimation, DoubleAnimation, PointAnimation, 它們均繼承自 Timeline
 */

using System;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Animation;

namespace Windows10.Animation
{
    public sealed partial class LinearAnimation : Page
    {
        public LinearAnimation()
        {
            this.InitializeComponent();

            this.Loaded += LinearAnimation_Loaded;
        }

        private void LinearAnimation_Loaded(object sender, RoutedEventArgs e)
        {
            // 啟動動畫
            storyboardPoint.Begin();

            // 停止動畫
            // storyboardPoint.Stop();



            // 用於演示如何在 CodeBehind 端定義 Storyboard
            ColorAnimation ca = new ColorAnimation();
            ca.BeginTime = TimeSpan.Zero;
            ca.From = Colors.Red;
            ca.To = Colors.Yellow;
            ca.Duration = TimeSpan.FromSeconds(3);
            ca.AutoReverse = true;
            ca.RepeatBehavior = new RepeatBehavior(3);
            Storyboard.SetTarget(ca, ellipse2);
            Storyboard.SetTargetProperty(ca, "(Fill).(Color)");

            Storyboard sb = new Storyboard();
            sb.Children.Add(ca);
            sb.Begin();
        }
    }
}


2、演示關鍵幀動畫的應用
Animation/KeyFrameAnimation.xaml

<Page
    x:Class="Windows10.Animation.KeyFrameAnimation"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Windows10.Animation"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="Transparent">
        <StackPanel Margin="10 0 10 10">

            <!--
                關鍵幀動畫一共有 4 種:
                    ColorAnimationUsingKeyFrames, DoubleAnimationUsingKeyFrames, PointAnimationUsingKeyFrames, ObjectAnimationUsingKeyFrames 它們均繼承自 Timeline
            
                ColorAnimationUsingKeyFrames 中的 KeyFrame 支持:
                    LinearColorKeyFrame, DiscreteColorKeyFrame, SplineColorKeyFrame, EasingColorKeyFrame
            
                DoubleAnimationUsingKeyFrames 中的 KeyFrame 支持:
                    LinearDoubleKeyFrame, DiscreteDoubleKeyFrame, SplineDoubleKeyFrame, EasingDoubleKeyFrame
            
                PointAnimationUsingKeyFrames 中的 KeyFrame 支持:
                    LinearPointKeyFrame, DiscretePointKeyFrame, SplinePointKeyFrame, EasingPointKeyFrame
            
                ObjectAnimationUsingKeyFrames 中的 KeyFrame 支持:
                    DiscreteObjectKeyFrame
            
                Linear 代表線性,Discrete 代表離散,Spline 代表三次貝塞爾曲線,Easing 代表緩動
            
                Value - 關鍵幀的目標值
                KeyTime - 到達關鍵幀目標值的時間
                KeySpline - 三次貝塞爾曲線的兩個控制點:x1,y1 x2,y2(該三次貝塞爾曲線的起點為0,0,終點為1,1)
            -->

            
            <!--
                ColorAnimationUsingKeyFrames
            -->
            <Grid Margin="5" HorizontalAlignment="Left">
                <Grid.Resources>
                    <BeginStoryboard x:Name="storyboardColor">
                        <Storyboard>
                            <ColorAnimationUsingKeyFrames Storyboard.TargetName="solidColorBrush" Storyboard.TargetProperty="Color" Duration="0:0:10">
                                <LinearColorKeyFrame Value="Green" KeyTime="0:0:3" />
                                <DiscreteColorKeyFrame Value="Blue" KeyTime="0:0:4" />
                                <SplineColorKeyFrame Value="Red" KeySpline="0.6,0.0 0.9,0.00" KeyTime="0:0:6" />
                                <EasingColorKeyFrame Value="Orange" KeyTime="0:0:8">
                                    <EasingColorKeyFrame.EasingFunction>
                                        <ElasticEase EasingMode="EaseInOut" />
                                    </EasingColorKeyFrame.EasingFunction>
                                </EasingColorKeyFrame>
                            </ColorAnimationUsingKeyFrames>
                        </Storyboard>
                    </BeginStoryboard>
                </Grid.Resources>
                <Rectangle Width="100" Height="50">
                    <Rectangle.Fill>
                        <SolidColorBrush x:Name="solidColorBrush" Color="Red" />
                    </Rectangle.Fill>
                </Rectangle>
            </Grid>


            <!--
                DoubleAnimationUsingKeyFrames
            -->
            <Grid Margin="5" HorizontalAlignment="Left">
                <Grid.Resources>
                    <BeginStoryboard x:Name="storyboardDouble">
                        <Storyboard>
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="translateTransform" Storyboard.TargetProperty="X" Duration="0:0:10">
                                <LinearDoubleKeyFrame Value="500" KeyTime="0:0:3" />
                                <DiscreteDoubleKeyFrame Value="400" KeyTime="0:0:4" />
                                <SplineDoubleKeyFrame Value="300" KeySpline="0.6,0.0 0.9,0.00" KeyTime="0:0:6" />
                                <EasingDoubleKeyFrame Value="200" KeyTime="0:0:8">
                                    <EasingDoubleKeyFrame.EasingFunction>
                                        <ElasticEase EasingMode="EaseInOut" />
                                    </EasingDoubleKeyFrame.EasingFunction>
                                </EasingDoubleKeyFrame>
                            </DoubleAnimationUsingKeyFrames>
                        </Storyboard>
                    </BeginStoryboard>
                </Grid.Resources>
                <Rectangle Fill="Red" Width="100" Height="50">
                    <Rectangle.RenderTransform>
                        <TranslateTransform x:Name="translateTransform" X="0" Y="0" />
                    </Rectangle.RenderTransform>
                </Rectangle>
            </Grid>


            <!--
                PointAnimationUsingKeyFrames
            -->
            <Grid Margin="5" HorizontalAlignment="Left">
                <Grid.Resources>
                    <BeginStoryboard x:Name="storyboardPoint">
                        <Storyboard>
                            <PointAnimationUsingKeyFrames Storyboard.TargetName="ellipseGeometry" Storyboard.TargetProperty="Center" Duration="0:0:10" 
                                                          EnableDependentAnimation="True">
                                <LinearPointKeyFrame Value="100,100" KeyTime="0:0:3" />
                                <DiscretePointKeyFrame Value="200,200" KeyTime="0:0:4" />
                                <SplinePointKeyFrame Value="300,300" KeySpline="0.6,0.0 0.9,0.00" KeyTime="0:0:6" />
                                <EasingPointKeyFrame Value="400,400" KeyTime="0:0:8">
                                    <EasingPointKeyFrame.EasingFunction>
                                        <ElasticEase EasingMode="EaseInOut" />
                                    </EasingPointKeyFrame.EasingFunction>
                                </EasingPointKeyFrame>
                            </PointAnimationUsingKeyFrames>
                        </Storyboard>
                    </BeginStoryboard>
                </Grid.Resources>
                <Path Fill="Red">
                    <Path.Data>
                        <EllipseGeometry x:Name="ellipseGeometry" Center="50,50" RadiusX="15" RadiusY="15" />
                    </Path.Data>
                </Path>
            </Grid>


            <!--
                ObjectAnimationUsingKeyFrames
            -->
            <Grid Margin="5" HorizontalAlignment="Left">
                <Grid.Resources>
                    <BeginStoryboard x:Name="storyboardObject">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="textBlock" Storyboard.TargetProperty="Text" Duration="0:0:10">
                                <DiscreteObjectKeyFrame KeyTime="0:0:1" Value="w" />
                                <DiscreteObjectKeyFrame KeyTime="0:0:2" Value="we" />
                                <DiscreteObjectKeyFrame KeyTime="0:0:3" Value="web" />
                                <DiscreteObjectKeyFrame KeyTime="0:0:4" Value="weba" />
                                <DiscreteObjectKeyFrame KeyTime="0:0:5" Value="webab" />
                                <DiscreteObjectKeyFrame KeyTime="0:0:6" Value="webabc" />
                                <DiscreteObjectKeyFrame KeyTime="0:0:7" Value="webabcd" />
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </BeginStoryboard>
                </Grid.Resources>
                <TextBlock x:Name="textBlock" Width="200" FontSize="32" Text="" />
            </Grid>

        </StackPanel>
    </Grid>
</Page>



OK
[源碼下載]


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 前言 MDK-ARM意思就是基於ARM的微控制器開發工具(Microcontroller Developer Kit),由Keil公司開發,MDK-ARM包含了工業標準的Keil C編譯器、巨集彙編器、調試器、實時內核等組件。具有業行領先的ARM C/C++編譯工具鏈,完美支持Cortex-M、Cor ...
  • 說一下剛學習uCOS的心得1)首先強調一下實時操作系統(RTOS)的特點,最明顯的是提供及時響應和高可靠性2)基於實施操作系統的應用程式設計中,其中很重要的一個概念是"任務",任務設計也就是任務函數的設計是整個整 個應用程式的基礎,其他軟體設計工作都是圍繞來展開的3)用戶任務函數中,必須包含至少一次 ...
  • ...
  • serdel是什麼 userdel 是一個底層用於刪除用戶的工具。在 Debian 上,我們通常會使用 deluser 命令。userdel 會查詢系統賬戶文件,例如 /etc/password 和 /etc/group。那麼它會刪除所有和用戶名相關的條目。在我們刪除它之前,用戶名必須存在。 如何使 ...
  • 預熱組件下載地址:下載地址 IIS預熱模塊配置界面插件:下載地址 Warm Up設定方式: (1) 應用程式池層級:只要有需要的應用程式池的Start Mode設定AlwaysRunning就可以 (2) 站點層級:選擇你們要做預熱的站點 通過以上兩步,就完成了warm up, 簡單吧。(IIS8 ...
  • - 什麼是性能調優?(what) - 為什麼需要性能調優?(why) - 什麼時候需要性能調優?(when) - 什麼地方需要性能調優?(where) - 什麼人來進行性能調優?(who) - 怎麼樣進行性能調優?(How) - 總結 # 什麼是性能調優?(what) # ![](http://i. ...
  • 1(1)庫文件:靜態庫文件 和 共用庫文件(2)比較a.靜態庫文件: 使用靜態庫文件時,直接把代碼/指令複製到目標文件中 目標文件會顯得比較龐大,修改和維護都不方便 可以脫離靜態庫文件,效率比較高 b.共用庫文件: 使用共用庫時,將代碼/指令所對應的地址複製到目標文件 目標文件會比較小,修改和維護比 ...
  • 最近由於項目需要,需要打開防火牆功能. 公司有 arm linux 3.0x86 linux 3.2x86 linux 2.4 的三個嵌入式.都需要打開防火牆功能. 執行“whereis iptables”命令,如果結果不為空,則說明防火牆軟體已安裝 輸入iptables -L 命令查看配置 此處為 ...
一周排行
    -Advertisement-
    Play Games
  • 示例項目結構 在 Visual Studio 中創建一個 WinForms 應用程式後,項目結構如下所示: MyWinFormsApp/ │ ├───Properties/ │ └───Settings.settings │ ├───bin/ │ ├───Debug/ │ └───Release/ ...
  • [STAThread] 特性用於需要與 COM 組件交互的應用程式,尤其是依賴單線程模型(如 Windows Forms 應用程式)的組件。在 STA 模式下,線程擁有自己的消息迴圈,這對於處理用戶界面和某些 COM 組件是必要的。 [STAThread] static void Main(stri ...
  • 在WinForm中使用全局異常捕獲處理 在WinForm應用程式中,全局異常捕獲是確保程式穩定性的關鍵。通過在Program類的Main方法中設置全局異常處理,可以有效地捕獲並處理未預見的異常,從而避免程式崩潰。 註冊全局異常事件 [STAThread] static void Main() { / ...
  • 前言 給大家推薦一款開源的 Winform 控制項庫,可以幫助我們開發更加美觀、漂亮的 WinForm 界面。 項目介紹 SunnyUI.NET 是一個基於 .NET Framework 4.0+、.NET 6、.NET 7 和 .NET 8 的 WinForm 開源控制項庫,同時也提供了工具類庫、擴展 ...
  • 說明 該文章是屬於OverallAuth2.0系列文章,每周更新一篇該系列文章(從0到1完成系統開發)。 該系統文章,我會儘量說的非常詳細,做到不管新手、老手都能看懂。 說明:OverallAuth2.0 是一個簡單、易懂、功能強大的許可權+可視化流程管理系統。 有興趣的朋友,請關註我吧(*^▽^*) ...
  • 一、下載安裝 1.下載git 必須先下載並安裝git,再TortoiseGit下載安裝 git安裝參考教程:https://blog.csdn.net/mukes/article/details/115693833 2.TortoiseGit下載與安裝 TortoiseGit,Git客戶端,32/6 ...
  • 前言 在項目開發過程中,理解數據結構和演算法如同掌握蓋房子的秘訣。演算法不僅能幫助我們編寫高效、優質的代碼,還能解決項目中遇到的各種難題。 給大家推薦一個支持C#的開源免費、新手友好的數據結構與演算法入門教程:Hello演算法。 項目介紹 《Hello Algo》是一本開源免費、新手友好的數據結構與演算法入門 ...
  • 1.生成單個Proto.bat內容 @rem Copyright 2016, Google Inc. @rem All rights reserved. @rem @rem Redistribution and use in source and binary forms, with or with ...
  • 一:背景 1. 講故事 前段時間有位朋友找到我,說他的窗體程式在客戶這邊出現了卡死,讓我幫忙看下怎麼回事?dump也生成了,既然有dump了那就上 windbg 分析吧。 二:WinDbg 分析 1. 為什麼會卡死 窗體程式的卡死,入口門檻很低,後續往下分析就不一定了,不管怎麼說先用 !clrsta ...
  • 前言 人工智慧時代,人臉識別技術已成為安全驗證、身份識別和用戶交互的關鍵工具。 給大家推薦一款.NET 開源提供了強大的人臉識別 API,工具不僅易於集成,還具備高效處理能力。 本文將介紹一款如何利用這些API,為我們的項目添加智能識別的亮點。 項目介紹 GitHub 上擁有 1.2k 星標的 C# ...