public override Storyboard GetAnimationStoryboard(string propertyToAnimate, AnimationTriggerValue triggerValue, GridLength newValue, GridLength oldValue) { GridAnimation animation = new GridAnimation() { To = triggerValue == AnimationTriggerValue.Start || triggerValue == AnimationTriggerValue.Unset ? newValue : oldValue, From = triggerValue == AnimationTriggerValue.Start || triggerValue == AnimationTriggerValue.Unset ? oldValue : newValue, Duration = triggerValue == AnimationTriggerValue.Unset ? TimeSpan.FromSeconds(0.3) : TimeSpan.FromSeconds(0.18), AccelerationRatio = triggerValue == AnimationTriggerValue.Unset ? 0.3 : 0.7, EasingFunction = new QuarticEase() }; Storyboard.SetTargetProperty(animation, new PropertyPath(propertyToAnimate)); Storyboard animationStoryboard = new Storyboard(); animationStoryboard.Children.Add(animation); return(animationStoryboard); }
/// <summary> /// Get stortyboard for animation /// </summary> /// <param name="propertyToAnimate"></param> /// <param name="newValue"></param> /// <param name="oldValue"></param> /// <returns></returns> public abstract Storyboard GetAnimationStoryboard(DependencyObject element, string propertyToAnimate, AnimationTriggerValue triggerValue, Property newValue, Property oldValue);
/// <summary> /// Check if element is FrameworkElement or FrameworkContentElement /// </summary> /// <returns></returns> public void GetAnimationStoryboardWithOldValueAndStart(DependencyObject element, string propertyToAnimate, AnimationTriggerValue triggerValue, Property newValue, Property oldValue) { if (element is FrameworkElement) { GetAnimationStoryboard(element, propertyToAnimate, triggerValue, newValue, oldValue).Begin(element as FrameworkElement); } else if (element is FrameworkContentElement) { GetAnimationStoryboard(element, propertyToAnimate, triggerValue, newValue, oldValue).Begin(element as FrameworkContentElement); } else { throw new ArgumentException("Element type must be FrameworkElement or FrameworkContentElement"); } }
/// <summary> /// Sets attached property with animation trigger /// </summary> /// <param name="animationPropertyProperty">The element to get the property from</param> /// <param name="value">New value</param> public static void SetAnimationTrigger(DependencyObject d, AnimationTriggerValue value) => d.SetValue(AnimationTriggerProperty, value);
/// <summary> /// Reverse <see cref="AnimationTriggerValue"/> /// If value set to Start it changes to StartReverce /// If value set to StartReverce it changes to Start /// </summary> /// <param name="value"></param> /// <returns></returns> public static AnimationTriggerValue ReverceAnimationTriggerValue(AnimationTriggerValue value) => value == AnimationTriggerValue.Start ? AnimationTriggerValue.StartReverce : AnimationTriggerValue.Start;
/// <summary> /// Get stortyboard for animation /// </summary> /// <param name="propertyToAnimate"></param> /// <param name="newValue"></param> /// <param name="oldValue"></param> /// <returns></returns> public abstract Storyboard GetAnimationStoryboard(string propertyToAnimate, AnimationTriggerValue triggerValue, Property newValue, Property oldValue);