瀏覽代碼

Added a looping example. Removed Easing from default type converters, adding an typeconverter attribute is enough.

Jumar Macato 7 年之前
父節點
當前提交
6860f3fc69

+ 35 - 10
samples/RenderTest/Pages/AnimationsPage.xaml

@@ -23,6 +23,16 @@
                 15,36 16.3809,34.9063 16.3809,34.9063C
                 16.3809,34.9063 10.1309,30.9062 16.6309,19.9063 Z"/>
         </Template>
+        <Template x:Key="Heart">
+          <Path Fill="Red" Stretch="Uniform" Data="
+          M 272.70141,238.71731 
+          C 206.46141,238.71731 152.70146,292.4773 152.70146,358.71731 
+          C 152.70146,493.47282 288.63461,528.80461 381.26391,662.02535 
+          C 468.83815,529.62199 609.82641,489.17075 609.82641,358.71731 
+          C 609.82641,292.47731 556.06651,238.7173 489.82641,238.71731 
+          C 441.77851,238.71731 400.42481,267.08774 381.26391,307.90481 
+          C 362.10311,267.08773 320.74941,238.7173 272.70141,238.71731 z "/>
+        </Template>
       </Styles.Resources>
       <Style Selector="Border.Test">
         <Setter Property="Margin" Value="15"/>
@@ -33,12 +43,9 @@
       </Style>
       <Style Selector="Border.Rect1:pointerover">
         <Style.Animations>
-          <Animation Duration="0:0:2.5"
+          <Animation Duration="0:0:2.5" 
                      RepeatBehavior="Repeat"
-                     RepeatCount="4"
-                     FillMode="None"
-                     PlaybackDirection="AlternateReverse"
-                     Easing="SineEaseInOut">
+                     RepeatCount="4" FillMode="None" PlaybackDirection="AlternateReverse" Easing="SineEaseInOut">
             <TransformKeyFrames Property="RotateTransform.Angle">
               <KeyFrame Cue="0%" Value="0"/>
               <KeyFrame Cue="100%" Value="0"/>
@@ -69,6 +76,23 @@
           </Animation>
         </Style.Animations>
       </Style>
+      <Style Selector="Border.Rect2a">
+        <Setter Property="Child" Value="{StaticResource Heart}"/>
+        <Style.Animations>
+          <Animation Duration="0:0:0.5" Easing="QuadraticEaseInOut" RepeatBehavior="Loop">
+            <TransformKeyFrames Property="ScaleTransform.ScaleX">
+              <KeyFrame Cue="0%" Value="1"/>
+              <KeyFrame Cue="50%" Value="0.8"/>
+              <KeyFrame Cue="100%" Value="1"/>
+            </TransformKeyFrames>
+            <TransformKeyFrames Property="ScaleTransform.ScaleY">
+              <KeyFrame Cue="0%" Value="1"/>
+              <KeyFrame Cue="50%" Value="0.8"/>
+              <KeyFrame Cue="100%" Value="1"/>
+            </TransformKeyFrames>
+          </Animation>
+        </Style.Animations>
+      </Style>
       <Style Selector="Border.Rect3:pointerover">
         <Style.Animations>
           <Animation Duration="0:0:3" Easing="BounceEaseInOut">
@@ -108,11 +132,12 @@
               <ScaleTransform/>
             </TransformGroup>
           </Border.RenderTransform>
-          <!-- <Border.Transitions>
-            <Transitions>
-              <DoubleTransition Property="Border.Opacity" Duration="0:0:2.5"/>
-            </Transitions>
-          </Border.Transitions> -->
+          <!-- <Border.Transitions><Transitions><DoubleTransition Property="Border.Opacity" Duration="0:0:2.5"/></Transitions></Border.Transitions> -->
+        </Border>
+        <Border Classes="Test Rect2a" Background="Transparent">
+          <Border.RenderTransform>
+            <ScaleTransform/>
+          </Border.RenderTransform>
         </Border>
         <Border Classes="Test Rect2" Background="DarkMagenta">
           <Border.RenderTransform>

+ 1 - 0
src/Avalonia.Animation/Easing.cs → src/Avalonia.Animation/Easing/Easing.cs

@@ -11,6 +11,7 @@ namespace Avalonia.Animation.Easings
     /// <summary>
     /// Base class for all Easing classes.
     /// </summary>
+    [TypeConverter(typeof(EasingTypeConverter))]
     public abstract class Easing : IEasing
     {
         /// <inheritdoc/>

+ 1 - 1
src/Markup/Avalonia.Markup.Xaml/Converters/EasingTypeConverter.cs → src/Avalonia.Animation/Easing/EasingTypeConverter.cs

@@ -6,7 +6,7 @@ using System;
 using System.ComponentModel;
 using System.Globalization;
 
-namespace Avalonia.Markup.Xaml.Converters
+namespace Avalonia.Animation.Easings
 {
 
     public class EasingTypeConverter : TypeConverter

+ 1 - 0
src/Avalonia.Animation/Keyframes/KeyFramesStateMachine`1.cs

@@ -11,6 +11,7 @@ namespace Avalonia.Animation.Keyframes
     {
         object _lastInterpValue;
         object _firstKFValue;
+        
         private ulong _delayTotalFrameCount,
             _durationTotalFrameCount,
             _delayFrameCount,

+ 0 - 1
src/Markup/Avalonia.Markup.Xaml/Avalonia.Markup.Xaml.csproj

@@ -31,7 +31,6 @@
         </Compile>
         <Compile Include="AvaloniaXamlLoaderPortableXaml.cs" />
         <Compile Include="AvaloniaXamlLoader.cs" />
-        <Compile Include="Converters\EasingTypeConverter.cs" />
         <Compile Include="Converters\CornerRadiusTypeConverter.cs" />
         <Compile Include="Converters\MatrixTypeConverter.cs" />
         <Compile Include="Converters\RectTypeConverter.cs" />

+ 0 - 2
src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaDefaultTypeConverters.cs

@@ -50,8 +50,6 @@ namespace Avalonia.Markup.Xaml.PortableXaml
             //{ typeof(Uri), typeof(Converters.UriTypeConverter) },
             { typeof(Cursor), typeof(CursorTypeConverter) },
             { typeof(WindowIcon), typeof(IconTypeConverter) },
-            { typeof(Easing), typeof(EasingTypeConverter) },
-            { typeof(IEasing), typeof(EasingTypeConverter) },
             //{ typeof(FontWeight), typeof(FontWeightConverter) },
         };