public static void AddOpacityAnimation(this Storyboard storyboard,
       UIElement fe, double from, double to, Duration duration,
       EasingFunctionBase easingFunction)
 {
     storyboard.AddAnimation(fe,
      storyboard.CreateDoubleAnimation(duration, from, to, easingFunction),
      UIElement.OpacityProperty);
 }
 public static void AddTranslationAnimation(this Storyboard storyboard,
 FrameworkElement fe, Point from, Point to, Duration duration,
 EasingFunctionBase easingFunction)
 {
     storyboard.AddAnimation(fe.RenderTransform,
            storyboard.CreateDoubleAnimation(duration, from.X, to.X, easingFunction),
               CompositeTransform.TranslateXProperty);
       storyboard.AddAnimation(fe.RenderTransform,
           storyboard.CreateDoubleAnimation(duration, from.Y, to.Y, easingFunction),
              CompositeTransform.TranslateYProperty);
 }
 public static void AddScalingAnimation(this Storyboard storyboard,
 FrameworkElement fe, double fromX, double toX, double fromY, double toY, Duration duration,
 EasingFunctionBase easingFunction)
 {
     storyboard.AddAnimation(fe.RenderTransform,
            storyboard.CreateDoubleAnimation(duration, fromX, toX, easingFunction),
               CompositeTransform.ScaleXProperty);
       storyboard.AddAnimation(fe.RenderTransform,
           storyboard.CreateDoubleAnimation(duration, fromY, toY, easingFunction),
              CompositeTransform.ScaleYProperty);
 }
Exemple #4
0
 public void GoTo(double targetOffset, Duration duration, EasingFunctionBase easingFunction, Action completionAction)
 {
     #if !WINDOWS_PHONE
     this.storyboard.SkipToFill();
     #endif
     this.animation.To = targetOffset;
     this.animation.Duration = duration;
     this.animation.EasingFunction = easingFunction;
     this.storyboard.Begin();
     this.storyboard.SeekAlignedToLastTick(TimeSpan.Zero);
     this.completionAction = completionAction;
 }
 public static Timeline CreateDoubleAnimation(this Storyboard storyboard,
 Duration duration, double from, double to, EasingFunctionBase easingFunction)
 {
     var animation = new DoubleAnimation
       {
     From = from,
     To = to,
     Duration = duration,
     EasingFunction = easingFunction
       };
       return animation;
 }
Exemple #6
0
 public static async Task AnimateHeightAsync(this FrameworkElement element, double height, double duration = 250, EasingFunctionBase easingFunction = null)
 {
     if (element.Height != height)
     {
         await AnimateDoublePropertyAsync(element, "Height", element.ActualHeight, height, duration, easingFunction);
     }
 }
        public static Storyboard Animate(this DependencyObject target, double from, double to, string propertyPath, int duration, int?startTime, EasingFunctionBase easing = null, Action completed = null)
        {
            DoubleAnimation doubleAnimation = new DoubleAnimation();

            doubleAnimation.To             = new double?(to);
            doubleAnimation.From           = new double?(from);
            doubleAnimation.EasingFunction = easing;
            doubleAnimation.Duration       = (Duration)TimeSpan.FromMilliseconds((double)duration);
            Storyboard.SetTarget((Timeline)doubleAnimation, target);
            Storyboard.SetTargetProperty((Timeline)doubleAnimation, new PropertyPath(propertyPath).Path);
            Storyboard storyboard = new Storyboard();

            if (startTime.HasValue)
            {
                storyboard.BeginTime = new TimeSpan?(TimeSpan.FromMilliseconds((double)startTime.Value));
            }
            else
            {
                storyboard.BeginTime = new TimeSpan?();
            }
            if (completed != null)
            {
                storyboard.Completed += ((s, e) => completed());
            }
            storyboard.Children.Add((Timeline)doubleAnimation);
            storyboard.Begin();
            return(storyboard);
        }
Exemple #8
0
        private Storyboard CreateTranslateStoryboard(double x, double y, DependencyObject element, TranslateTransform translate, EasingFunctionBase easing, double duration = 0.8)
        {
            var sb = new Storyboard();

            var dax = new DoubleAnimation();

            Storyboard.SetTarget(dax, translate);
            Storyboard.SetTargetProperty(dax, "X");
            dax.To             = x;
            dax.Duration       = TimeSpan.FromSeconds(duration);
            dax.EasingFunction = easing;
            sb.Children.Add(dax);


            var day = new DoubleAnimation();

            Storyboard.SetTarget(day, translate);
            Storyboard.SetTargetProperty(day, "Y");
            day.To             = y;
            day.Duration       = TimeSpan.FromSeconds(duration);
            day.EasingFunction = easing;
            sb.Children.Add(day);

            var wdax = new DoubleAnimation();

            Storyboard.SetTarget(wdax, element);
            Storyboard.SetTargetProperty(wdax, "Win2DTranslateX");
            wdax.To                       = x;
            wdax.Duration                 = TimeSpan.FromSeconds(duration);
            wdax.EasingFunction           = easing;
            wdax.EnableDependentAnimation = true;
            sb.Children.Add(wdax);


            var wday = new DoubleAnimation();

            Storyboard.SetTarget(wday, element);
            Storyboard.SetTargetProperty(wday, "Win2DTranslateY");
            wday.To                       = y;
            wday.Duration                 = TimeSpan.FromSeconds(duration);
            wday.EasingFunction           = easing;
            wday.EnableDependentAnimation = true;
            sb.Children.Add(wday);

            return(sb);
        }
Exemple #9
0
 public void GoTo(double targetOffset, Duration duration, EasingFunctionBase easingFunction)
 {
     this.GoTo(targetOffset, duration, easingFunction, null);
 }
Exemple #10
0
 public static Storyboard AnimateScaleY(this FrameworkElement element, double y, double duration = 150, EasingFunctionBase easingFunction = null)
 {
     if (element.GetScaleY() != y)
     {
         return(AnimateDoubleProperty(element.GetCompositeTransform(), "ScaleY", element.GetScaleY(), y, duration, easingFunction));
     }
     return(null);
 }
        private DoubleAnimation CreateDouble(double to, int duration, DependencyObject target, string path, EasingFunctionBase easing)
        {
            var anim = new DoubleAnimation();

            anim.To             = to;
            anim.Duration       = new Duration(TimeSpan.FromMilliseconds(duration));
            anim.EasingFunction = easing;

            Storyboard.SetTarget(anim, target);
#if SILVERLIGHT
            Storyboard.SetTargetProperty(anim, new PropertyPath(path));
#else
            Storyboard.SetTargetProperty(anim, path);
#endif

            return(anim);
        }
        private void OnEasingFunctionRadioButtonChecked(object sender, RoutedEventArgs e)
        {
            RadioButton radioButton = sender as RadioButton;
            Type        type        = radioButton.Tag as Type;

            easingFunction = null;
            propertiesStackPanel.Children.Clear();

            // typeがnullになるのは"None"ボタンの場合のみ
            if (type != null)
            {
                TypeInfo typeInfo = type.GetTypeInfo();

                // パラメータなしのコンストラクタを取得し、イージング関数をインスタンス化
                foreach (ConstructorInfo constructorInfo in typeInfo.DeclaredConstructors)
                {
                    if (constructorInfo.IsPublic && constructorInfo.GetParameters().Length == 0)
                    {
                        easingFunction = constructorInfo.Invoke(null) as EasingFunctionBase;
                        break;
                    }
                }

                // イージング関数のプロパティを列挙
                foreach (PropertyInfo property in typeInfo.DeclaredProperties)
                {
                    // int型とdouble型のプロパティだけを処理
                    if (property.PropertyType != typeof(int) &&
                        property.PropertyType != typeof(double))
                    {
                        continue;
                    }

                    // プロパティ名を表示するためのTextBlockを作成
                    TextBlock txtblk = new TextBlock
                    {
                        Text = property.Name + ":",
                    };
                    propertiesStackPanel.Children.Add(txtblk);

                    // プロパティ値を表すSlider
                    Slider slider = new Slider
                    {
                        Width   = 144,
                        Minimum = 0,
                        Maximum = 10,
                        Tag     = property,
                    };

                    if (property.PropertyType == typeof(int))
                    {
                        slider.SmallChange = 1;
                        slider.Value       = (int)property.GetValue(easingFunction);
                    }
                    else
                    {
                        slider.SmallChange = 0.1;
                        slider.Value       = (double)property.GetValue(easingFunction);
                    }

                    // Sliderのイベントハンドラを定義
                    slider.ValueChanged += (sliderSender, sliderArgs) =>
                    {
                        Slider       sliderChanging = sliderSender as Slider;
                        PropertyInfo propertyInfo   = sliderChanging.Tag as PropertyInfo;

                        if (property.PropertyType == typeof(int))
                        {
                            property.SetValue(easingFunction, (int)sliderArgs.NewValue);
                        }
                        else
                        {
                            property.SetValue(easingFunction, (double)sliderArgs.NewValue);
                        }
                        DrawNewGraph();
                    };
                    propertiesStackPanel.Children.Add(slider);
                }
            }

            // EasingModeを表すRadioButtonを初期化
            foreach (UIElement child in easingModeStackPanel.Children)
            {
                RadioButton easingModeRadioButton = child as RadioButton;
                easingModeRadioButton.IsEnabled = easingFunction != null;

                easingModeRadioButton.IsChecked = easingFunction != null &&
                                                  easingFunction.EasingMode == (EasingMode)easingModeRadioButton.Tag;
            }

            DrawNewGraph();
        }
Exemple #13
0
        public static void UpdateViewRect(Grid gSlideBox, bool bScaleChanged, bool animate = false, float fDurationTime = 0f, EasingFunctionBase easing = null)
        {
            MultiScaleImage mSlide       = gSlideBox.FindName("mMultiScaleImage") as MultiScaleImage;
            ZoomableCanvas  zcCycleGrid  = gSlideBox.FindName("zcGrid") as ZoomableCanvas;
            Border          border       = gSlideBox.FindName("bGridBox") as Border;
            float           fTargetScale = mSlide.fTargetScale;

            if (zcCycleGrid.Children.Count == 0)
            {
                return;
            }
            System.Windows.Point point = mSlide.SlideRatioToBoxPixel(new System.Windows.Point(0.0, 0.0));
            int elementActualAngle     = PublicMethods.GetElementActualAngle(mSlide);

            if (!animate)
            {
                zcCycleGrid.ApplyAnimationClock(ZoomableCanvas.ScaleProperty, null);
                border.ApplyAnimationClock(FrameworkElement.MarginProperty, null);
                border.Margin     = new Thickness(point.X, point.Y, 0.0, 0.0);
                zcCycleGrid.Scale = fTargetScale;
                if (bScaleChanged)
                {
                    foreach (System.Windows.Shapes.Rectangle child in zcCycleGrid.Children)
                    {
                        child.StrokeThickness = 1f / fTargetScale;
                    }
                }
            }
            else
            {
                border.BeginAnimation(FrameworkElement.MarginProperty, new ThicknessAnimation(new Thickness(point.X, point.Y, 0.0, 0.0), TimeSpan.FromMilliseconds(fDurationTime))
                {
                    EasingFunction = easing
                }, HandoffBehavior.Compose);
                if (bScaleChanged)
                {
                    DoubleAnimation doubleAnimation = new DoubleAnimation(fTargetScale, TimeSpan.FromMilliseconds(fDurationTime))
                    {
                        EasingFunction = easing
                    };
                    int i = 0;
                    doubleAnimation.CurrentTimeInvalidated += delegate
                    {
                        Task.Factory.StartNew(delegate
                        {
                            i++;
                            if (i % 3 == 0)
                            {
                                float fCurrentScale = 0f;
                                zcCycleGrid.Dispatcher.BeginInvoke((Action) delegate
                                {
                                    fCurrentScale = mSlide.GetCurrentScale();
                                    foreach (System.Windows.Shapes.Rectangle child2 in zcCycleGrid.Children)
                                    {
                                        child2.StrokeThickness = 1f / fCurrentScale;
                                    }
                                }, DispatcherPriority.Loaded);
                            }
                        }, TaskCreationOptions.AttachedToParent);
                    };
                    zcCycleGrid.BeginAnimation(ZoomableCanvas.ScaleProperty, doubleAnimation, HandoffBehavior.Compose);
                }
            }
            System.Windows.Point point3 = border.RenderTransformOrigin = new System.Windows.Point(0.0, 0.0);
            border.RenderTransform = new RotateTransform(elementActualAngle);
        }
        private void EasingChanged()
        {
            if (cboEasingFunction.SelectedIndex == -1 || cboEasingMode.SelectedIndex == -1)
            {
                return;
            }

            storyboard.Stop();

            EasingFunctionBase easingFunction = null;

            // 确定 Easing Function
            switch ((cboEasingFunction.SelectedItem as ComboBoxItem).Content.ToString())
            {
            case "BackEase":
                // Amplitude - 幅度,必须大于等于 0,默认值 1
                easingFunction = new BackEase()
                {
                    Amplitude = 1
                };
                break;

            case "BounceEase":
                // Bounces - 弹跳次数,必须大于等于 0,默认值 3
                // Bounciness - 弹跳程度,必须是正数,默认值 2
                easingFunction = new BounceEase()
                {
                    Bounces = 3, Bounciness = 2
                };
                break;

            case "CircleEase":
                easingFunction = new CircleEase();
                break;

            case "CubicEase":
                easingFunction = new CubicEase();
                break;

            case "ElasticEase":
                // Oscillations - 来回滑动的次数,必须大于等于 0,默认值 3
                // Springiness - 弹簧的弹度,必须是正数,默认值 3
                easingFunction = new ElasticEase()
                {
                    Oscillations = 3, Springiness = 3
                };
                break;

            case "ExponentialEase":
                easingFunction = new ExponentialEase();
                break;

            case "PowerEase":
                easingFunction = new PowerEase();
                break;

            case "QuadraticEase":
                easingFunction = new QuadraticEase();
                break;

            case "QuarticEase":
                easingFunction = new QuarticEase();
                break;

            case "QuinticEase":
                easingFunction = new QuinticEase();
                break;

            case "SineEase":
                easingFunction = new SineEase();
                break;

            default:
                break;
            }

            // 确定 Easing Mode
            switch ((cboEasingMode.SelectedItem as ComboBoxItem).Content.ToString())
            {
            case "EaseIn":     // 渐进
                easingFunction.EasingMode = EasingMode.EaseIn;
                break;

            case "EaseOut":     // 渐出(默认值)
                easingFunction.EasingMode = EasingMode.EaseOut;
                break;

            case "EaseInOut":     // 前半段渐进,后半段渐出
                easingFunction.EasingMode = EasingMode.EaseInOut;
                break;

            default:
                break;
            }

            // 用于演示缓动效果
            aniEasingDemo.EasingFunction = easingFunction;
            // 用于演示缓动轨迹
            aniBallY.EasingFunction = easingFunction;

            // 画出当前缓动的曲线图
            DrawEasingGraph(easingFunction);

            storyboard.Begin();
        }
Exemple #15
0
 public static async Task AnimateWidthAsync(this FrameworkElement element, double width, double duration = 250, EasingFunctionBase easingFunction = null)
 {
     if (element.ActualWidth != width)
     {
         await AnimateDoublePropertyAsync(element, "Width", element.ActualWidth, width, duration, easingFunction);
     }
 }
Exemple #16
0
        public static Storyboard AnimateWidth(this FrameworkElement element, double width, double duration = 250, EasingFunctionBase easingFunction = null)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            if (element.ActualWidth != width)
            {
                return(AnimateDoubleProperty(element, "Width", element.ActualWidth, width, duration, easingFunction));
            }
            return(null);
        }
Exemple #17
0
 public static async Task AnimateScaleYAsync(this FrameworkElement element, double y, double duration = 150, EasingFunctionBase easingFunction = null)
 {
     if (element.GetScaleY() != y)
     {
         await AnimateDoublePropertyAsync(element.GetCompositeTransform(), "ScaleY", element.GetScaleY(), y, duration, easingFunction);
     }
 }
Exemple #18
0
        static void StartAnimation(DependencyObject target, CSSEquivalent cssEquivalent, double?from, object to, Duration Duration, EasingFunctionBase easingFunction, string visualStateGroupName, DependencyProperty dependencyProperty, Action callbackForWhenfinished = null)
        {
            if (cssEquivalent.Name != null && cssEquivalent.Name.Count != 0)
            {
                UIElement uiElement = cssEquivalent.UIElement ?? (target as UIElement); // If no UIElement is specified, we assume that the property is intended to be applied to the instance on which the PropertyChanged has occurred.

                bool hasTemplate = (uiElement is Control) && ((Control)uiElement).HasTemplate;

                if (!hasTemplate || cssEquivalent.ApplyAlsoWhenThereIsAControlTemplate)
                {
                    if (cssEquivalent.DomElement == null && uiElement != null)
                    {
                        cssEquivalent.DomElement = uiElement.INTERNAL_OuterDomElement; // Default value
                    }
                    if (cssEquivalent.DomElement != null)
                    {
                        if (cssEquivalent.Value == null)
                        {
                            cssEquivalent.Value = (finalInstance, value) => { return(value ?? ""); }; // Default value
                        }
                        object cssValue = cssEquivalent.Value(target, to);

                        object newObj = CSHTML5.Interop.ExecuteJavaScriptAsync(@"new Object()");

                        if (AnimationHelpers.IsValueNull(from)) //todo: when using Bridge, I guess we would want to directly use "from == null" since it worked in the first place (I think).
                        {
                            foreach (string csspropertyName in cssEquivalent.Name)
                            {
                                CSHTML5.Interop.ExecuteJavaScriptAsync(@"$0[$1] = $2;", newObj, csspropertyName, cssValue);
                            }
                        }
                        else
                        {
                            foreach (string csspropertyName in cssEquivalent.Name)
                            {
                                CSHTML5.Interop.ExecuteJavaScriptAsync(@"$0[$1] = [$2, $3];", newObj, csspropertyName, cssValue, from);
                            }
                        }
                        AnimationHelpers.CallVelocity(cssEquivalent.DomElement, Duration, easingFunction, visualStateGroupName, callbackForWhenfinished, newObj);
                        target.DirtyVisualValue(dependencyProperty);
                    }
                }
            }
            else
            {
                throw new InvalidOperationException("Please set the Name property of the CSSEquivalent class.");
            }
        }
        /// <summary>
        /// Fades the element out using a custom DoubleAnimation of the Opacity property.
        /// </summary>
        /// <param name="element"></param>
        /// <param name="duration"></param>
        /// <param name="easingFunction"> </param>
        /// <returns></returns>
        public static void FadeOutCustom(this UIElement element, TimeSpan?duration = null, EasingFunctionBase easingFunction = null)
        {
            CleanUpPreviousFadeStoryboard(element);

            var fadeOutStoryboard = new Storyboard();
            var fadeOutAnimation  = new DoubleAnimation();

            if (duration == null)
            {
                duration = TimeSpan.FromSeconds(0.4);
            }

            fadeOutAnimation.Duration       = duration.Value;
            fadeOutAnimation.To             = 0.0;
            fadeOutAnimation.EasingFunction = easingFunction;

            Storyboard.SetTarget(fadeOutAnimation, element);
            Storyboard.SetTargetProperty(fadeOutAnimation, "Opacity");
            fadeOutStoryboard.Children.Add(fadeOutAnimation);
            SetAttachedFadeStoryboard(element, fadeOutStoryboard);
            fadeOutStoryboard.Begin();
            element.Opacity = 0.0;
            fadeOutStoryboard.Stop();
        }
Exemple #20
0
        public Storyboard CreateDepth3DIn(
            IEnumerable <FrameworkElement> items,
            FrameworkElement container     = null,
            double startDepth              = -300,
            TimeSpan?customStagger         = null,
            TimeSpan?customOpacityDuration = null,
            TimeSpan?customElementDuration = null,
            EasingFunctionBase customEase  = null)
        {
            // 0. Prepare ourselves a nice list of visible framework elements to animate
            var _items = items.ToList();

            // 1. Ensure perspective transform on the target parent to allow depth animations
            //    to work
            container?.GetPerspectiveTransform3D();

            // 2. Create the return storyboard, and the properties we're going to use
            var sb          = new Storyboard();
            var startOffset = TimeSpan.FromSeconds(0);
            var staggerTime = customStagger != null && customStagger.HasValue
                ? customStagger.Value
                : TimeSpan.FromMilliseconds(60);
            var duration = customElementDuration != null && customElementDuration.HasValue
                ? customElementDuration.Value
                : TimeSpan.FromMilliseconds(500);
            var durationOpacity = customOpacityDuration != null && customOpacityDuration.HasValue
                ? customOpacityDuration.Value
                : TimeSpan.FromMilliseconds(300);

            // 3. Now let's build the storyboard!
            for (var i = 0; i < _items.Count; i++)
            {
                // 3.0. Get the item and it's opacity
                var item = _items[i];
                item.GetCompositeTransform3D();

                double targetOpacity = 1;// item.Opacity;
                item.Opacity = 0;

                // 3.1. Check AddedDelay
                startOffset = startOffset.Add(Animation.GetAddedDelay(item));

                // 3.2. Animate the opacity
                sb.CreateTimeline <DoubleAnimationUsingKeyFrames>(item, TargetProperty.Opacity)
                .AddEasingDoubleKeyFrame(TimeSpan.Zero, 0)
                .AddEasingDoubleKeyFrame(startOffset, 0)
                .AddSplineDoubleKeyFrame(startOffset.Add(durationOpacity), targetOpacity, KeySplines.PerspectiveZoomOpacity);

                // 3.3. Animate the 3D depth translation
                if (startDepth != 0)
                {
                    var dbX = sb.CreateTimeline <DoubleAnimationUsingKeyFrames>(item, TargetProperty.CompositeTransform3D.TranslateZ)
                              .AddEasingDoubleKeyFrame(0, startDepth)
                              .AddEasingDoubleKeyFrame(startOffset, startDepth);

                    if (customEase == null)
                    {
                        dbX.AddSplineDoubleKeyFrame(startOffset.Add(duration), 0, KeySplines.EntranceTheme);
                    }
                    else
                    {
                        dbX.AddEasingDoubleKeyFrame(startOffset.Add(duration), 0, customEase);
                    }
                }

                // 3.4. Increment start offset
                startOffset = startOffset.Add(staggerTime);
            }

            return(sb);
        }
Exemple #21
0
        public static void PopUIElement(
            Windows.UI.Xaml.UIElement element,
            double scaleWidthFrom,
            double scaleWidthTo,
            double scaleHeightFrom,
            double scaleHeightTo,
            double moveWidthFrom,
            double moveWidthTo,
            double moveHeightFrom,
            double moveHeightTo,
            EasingFunctionBase easingFunc)
        {
            // animation
            element.RenderTransform = new CompositeTransform();
            Storyboard      sb     = new Storyboard();
            DoubleAnimation scalex = new DoubleAnimation()
            {
                From           = scaleWidthFrom,
                To             = scaleWidthTo,
                Duration       = TimeSpan.FromSeconds(inAnimationDurationSec),
                EasingFunction = easingFunc
            };
            DoubleAnimation scaley = new DoubleAnimation()
            {
                From           = scaleHeightFrom,
                To             = scaleHeightTo,
                Duration       = TimeSpan.FromSeconds(inAnimationDurationSec),
                EasingFunction = easingFunc
            };
            DoubleAnimation movex = new DoubleAnimation()
            {
                // move from the center of the cell to its left
                From           = moveWidthFrom,
                To             = moveWidthTo,
                Duration       = TimeSpan.FromSeconds(inAnimationDurationSec),
                EasingFunction = easingFunc
            };
            DoubleAnimation movey = new DoubleAnimation()
            {
                // move from the center of the cell to its top
                From           = moveHeightFrom,
                To             = moveHeightTo,
                Duration       = TimeSpan.FromSeconds(inAnimationDurationSec),
                EasingFunction = easingFunc
            };

            sb.Children.Add(scalex);
            sb.Children.Add(scaley);
            Storyboard.SetTargetProperty(scalex, "(UIElement.RenderTransform).(ScaleTransform.ScaleX)");
            Storyboard.SetTargetProperty(scaley, "(UIElement.RenderTransform).(ScaleTransform.ScaleY)");
            Storyboard.SetTarget(scalex, element);
            Storyboard.SetTarget(scaley, element);

            sb.Children.Add(movex);
            sb.Children.Add(movey);
            Storyboard.SetTargetProperty(movex, "(UIElement.RenderTransform).(CompositeTransform.TranslateX)");
            Storyboard.SetTargetProperty(movey, "(UIElement.RenderTransform).(CompositeTransform.TranslateY)");
            Storyboard.SetTarget(movex, element);
            Storyboard.SetTarget(movey, element);

            sb.Begin();
        }
 public OpacityAnimation(double opacity, TimeSpan duration, EasingFunctionBase easingFunction = null)
 {
     Opacity        = opacity;
     Duration       = duration;
     EasingFunction = easingFunction;
 }
 /// <summary>
 /// Provides derived classes an opportunity to handle changes to the ElementEasing property.
 /// </summary>
 /// <param name="oldElementEasing">Old Value</param>
 /// <param name="newElementEasing">New Value</param>
 ///
 protected virtual void OnElementEasingChanged(EasingFunctionBase oldElementEasing, EasingFunctionBase newElementEasing)
 {
 }
        public static Task AnimateDoublePropertyAsync(this DependencyObject target, string property, double from, double to, double duration = 250, EasingFunctionBase easingFunction = null)
        {
            TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>();
            Storyboard storyboard           = AnimateDoubleProperty(target, property, from, to, duration, easingFunction);

            storyboard.Completed += (sender, e) =>
            {
                tcs.SetResult(true);
            };
            return(tcs.Task);
        }
Exemple #25
0
 public static async Task AnimateXAsync(this FrameworkElement element, double x, double duration = 250, EasingFunctionBase easingFunction = null)
 {
     if (element.GetTranslateX() != x)
     {
         await AnimateDoublePropertyAsync(element.GetCompositeTransform(), "TranslateX", element.GetTranslateX(), x, duration, easingFunction);
     }
 }
Exemple #26
0
        // Function that will animate sliding a UI element to a new position.
        public void SlideElement(UIElement target, Orientation orientation, double?from, double to, int duration = 400, int startTime = 0, EasingFunctionBase easing = null)
        {
            // Use an ExponentialEase easing function if none was passed in.
            if (easing == null)
            {
                easing = new ExponentialEase();
            }

            // Create a transformation for the element.
            var transform = target.RenderTransform as CompositeTransform;

            if (transform == null)
            {
                transform = new CompositeTransform();
                target.RenderTransform = transform;
            }
            target.RenderTransformOrigin = new Windows.Foundation.Point(0.5, 0.5);

            // Create the animation and specify the to/from locations, easing function, and duration.
            DoubleAnimation slideAnimation = new DoubleAnimation
            {
                To             = to,
                From           = from,
                EasingFunction = easing,
                Duration       = TimeSpan.FromMilliseconds(duration)
            };

            // Set the target for the animation and define the target property (translate the X or Y axis).
            Storyboard.SetTarget(slideAnimation, target);
            string axis = orientation == Orientation.Horizontal ? "X" : "Y";

            Storyboard.SetTargetProperty(slideAnimation, $"(UIElement.RenderTransform).(CompositeTransform.Translate{axis})");

            // Create a new storyboard and specify the start time.
            Storyboard slideStoryboard = new Storyboard
            {
                BeginTime = TimeSpan.FromMilliseconds(startTime)
            };

            // Add the slide animation and start it.
            slideStoryboard.Children.Add(slideAnimation);
            slideStoryboard.Begin();
        }
        public static Storyboard AnimateDoubleProperty(this DependencyObject target, string property, double from, double to, double duration = 250, EasingFunctionBase easingFunction = null)
        {
            var storyboard = new Storyboard();
            var animation  = new DoubleAnimation
            {
                From                     = from,
                To                       = to,
                Duration                 = TimeSpan.FromMilliseconds(duration),
                EasingFunction           = easingFunction ?? new SineEase(),
                FillBehavior             = FillBehavior.HoldEnd,
                EnableDependentAnimation = true
            };

            Storyboard.SetTarget(animation, target);
            Storyboard.SetTargetProperty(animation, property);

            storyboard.Children.Add(animation);
            storyboard.FillBehavior = FillBehavior.HoldEnd;
            storyboard.Begin();

            return(storyboard);
        }
 /// <summary>
 /// Provides derived classes an opportunity to handle changes to the DragEasing property.
 /// </summary>
 /// <param name="oldDragEasing">Old Value</param>
 /// <param name="newDragEasing">New Value</param>
 protected virtual void OnDragEasingChanged(EasingFunctionBase oldDragEasing, EasingFunctionBase newDragEasing)
 {
 }
 public static async Task AnimateXAsync(this FrameworkElement element, double x, double duration = 250, EasingFunctionBase easingFunction = null)
 {
     if (element.GetTranslateX() != x)
     {
         // await element.Offset(offsetX: (float)element.GetTranslateX(), offsetY: 0, duration: duration, delay: 0, easingType: EasingType.Default).StartAsync();  //Offset animation can be awaited
         await AnimateDoublePropertyAsync(element.GetCompositeTransform(), "TranslateX", element.GetTranslateX(), x, duration, easingFunction);
     }
 }
Exemple #30
0
        private static DoubleAnimation CreateAnimation(double to, DependencyObject target, string propertyName, EasingFunctionBase ease, bool enableDependentAnimation)
        {
            var animation = new DoubleAnimation()
            {
                To       = to,
                Duration = TimeSpan.FromMilliseconds(300),
                EnableDependentAnimation = enableDependentAnimation,
                EasingFunction           = ease
            };

            Storyboard.SetTarget(animation, target);
            Storyboard.SetTargetProperty(animation, propertyName);

            return(animation);
        }
 public static Storyboard FadeIn(this UIElement element, double duration = 250, EasingFunctionBase easingFunction = null)
 {
     if (element == null)
     {
         throw new ArgumentNullException("element");
     }
     if (element.Opacity < 1.0)
     {
         return(AnimateDoubleProperty(element, "Opacity", element.Opacity, 1.0, duration, easingFunction));
     }
     return(null);
 }
        /// <summary>
        /// Add an animation to the current storyboard
        /// </summary>
        public static void AddAnimation(Storyboard storyboard, DependencyObject element, int duration, double toValue, string propertyPath, EasingFunctionBase easingFunction = null)
        {
            DoubleAnimation timeline = new DoubleAnimation
            {
                To       = toValue,
                Duration = TimeSpan.FromMilliseconds(duration)
            };

            if (easingFunction != null)
            {
                timeline.EasingFunction = easingFunction;
            }

            storyboard.Children.Add(timeline);

            Storyboard.SetTarget(timeline, element);
            Storyboard.SetTargetProperty(timeline, propertyPath);
        }
Exemple #33
0
 public static Storyboard AnimateX(this FrameworkElement element, double x, double duration = 250, EasingFunctionBase easingFunction = null)
 {
     if (element.GetTranslateX() != x)
     {
         return(AnimateDoubleProperty(element.GetCompositeTransform(), "TranslateX", element.GetTranslateX(), x, duration, easingFunction));
     }
     return(null);
 }
 public static async Task FadeInAsync(this UIElement element, double duration = 250, EasingFunctionBase easingFunction = null)
 {
     if (element.Opacity < 1.0)
     {
         await AnimateDoublePropertyAsync(element, "Opacity", element.Opacity, 1.0, duration, easingFunction);
     }
 }
Exemple #35
0
 public static Storyboard AnimateHeight(this FrameworkElement element, double height, double duration = 250, EasingFunctionBase easingFunction = null)
 {
     if (element == null)
     {
         throw new ArgumentNullException("element");
     }
     if (element.Height != height)
     {
         return(AnimateDoubleProperty(element, "Height", element.ActualHeight, height, duration, easingFunction));
     }
     return(null);
 }
Exemple #36
0
        private static DoubleAnimation CreateDoubleAnimation(DependencyObject target, string propertyPath, EasingFunctionBase easingFunc, double to, double duration)
        {
            var anim = new DoubleAnimation()
            {
                To             = to,
                Duration       = new Duration(TimeSpan.FromMilliseconds(duration)),
                EasingFunction = easingFunc
            };

            Storyboard.SetTarget(anim, target);
            Storyboard.SetTargetProperty(anim, propertyPath);
            return(anim);
        }
        private DoubleAnimation CreateDouble(double to, int duration, DependencyObject target, string path, EasingFunctionBase easing)
        {
            var anim = new DoubleAnimation();
            anim.To = to;
            anim.Duration = new Duration(TimeSpan.FromMilliseconds(duration));
            anim.EasingFunction = easing;

            Storyboard.SetTarget(anim, target);
#if SILVERLIGHT
            Storyboard.SetTargetProperty(anim, new PropertyPath(path));
#else
            Storyboard.SetTargetProperty(anim, path);
#endif

            return anim;
        }