# Customizing Animation for Rating Control

## Content



Rating for WPF provides the option to customize the animation effect by inheriting the properties and methods of the [IAnimationFactory](/componentone/api/wpf/online-extended/dotnet-framework-api/C1.WPF.Extended.4.6.2/C1.WPF.Extended.IAnimationFactory.html) class. Besides default collection of animation effects, users can customize the animation effects to apply to the Rating control.

### In Code

1.  Add the following code in the interaction logic for XAML to create an instance of CustomAnimationFlickerFactory class.
    
    ```csharp
    private IAnimationFactory customAnimationFlickerFactory = new CustomAnimationFlickerFactory();
    public MainWindow()
    {
        InitializeComponent();
        c1Rating.AnimationFactory = customAnimationFlickerFactory;
    }
    ```
    
    <br />
2.  Copy the following code and add to CustomAnimationFlickerFactory.cs file to override IAnimationFactory class.
    
    ```csharp
    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;
            }
        }
    }
    ```
    
    <br />
3.  Press **F5** to run the application and notice that a customized flickering effect is applied to the Rating control.