Rating for WPF provides the option to customize the animation effect by inheriting the properties and methods of the IAnimationFactory class. Besides default collection of animation effects, users can customize the animation effects to apply to the Rating control.
C# |
Copy Code
|
---|---|
private IAnimationFactory customAnimationFlickerFactory = new CustomAnimationFlickerFactory(); public MainWindow() { InitializeComponent(); c1Rating.AnimationFactory = customAnimationFlickerFactory; } |
C# |
Copy Code
|
---|---|
using C1.WPF.Extended; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Media.Media3D; namespace Rating_WPF_Animation { class CustomAnimationFlickerFactory : IAnimationFactory { public Storyboard GetForwardAnimation(FrameworkElement target, AnimationType animationType) { return GetFadeAnimation(target, true); } public Storyboard GetBackwardAnimation(FrameworkElement target, AnimationType animationType) { return GetFadeAnimation(target, false); } private Storyboard GetFadeAnimation(FrameworkElement target, bool forward) { RotateTransform st = new RotateTransform(); st.Angle = 360; Point p = new Point(0.5, 0.5); target.RenderTransformOrigin = p; target.RenderTransform = st; Storyboard sb = new Storyboard(); var duration = TimeSpan.FromSeconds(0.25); EasingFunctionBase easing = new ElasticEase() { EasingMode = EasingMode.EaseInOut, Oscillations = 20, Springiness = 5 }; DoubleAnimation da1 = new DoubleAnimation(); DoubleAnimation da2 = new DoubleAnimation(); if (forward) { da1.From = 1.0; da1.To = 0.0; da2.To = 1.0; } else { da1.From = 0.0; da1.To = 1.0; } da1.Duration = duration; da2.Duration = duration; da1.EasingFunction = easing; da2.EasingFunction = easing; sb.Children.Add(da1); sb.Children.Add(da2); Storyboard.SetTargetProperty(da2, new PropertyPath("RenderTransform.Angle")); Storyboard.SetTargetProperty(da1, new PropertyPath("Opacity")); return sb; } } } |