/// <summary> /// Called when the <see cref="ExtendedVisualStateManager"/> transitions to the element. /// The timeline which gets returned by this method is then used as a transitioning animation. /// </summary> /// <param name="toTimeline"> /// The animation, for which a visual transition timeline should be generated. /// The VisualStateManager wants to transition to this timeline. /// By default, this can only be an animation of the same type as this class. /// </param> /// <param name="easingFunction"> /// An easing function to be applied to the resulting timeline. /// Can be null. /// </param> /// <returns> /// A <see cref="Timeline"/> which displays a visual transition to this element. /// </returns> public override Timeline CreateToTransitionTimeline(Timeline toTimeline, IEasingFunction easingFunction) { var animation = (EasingFromToByAnimationBase <T>)base.CreateToTransitionTimeline(toTimeline, easingFunction); animation.EasingFunction = easingFunction; return(animation); }
static AccordionPanel() { var animationDuration = new Duration (TimeSpan.FromMilliseconds(400)); IEasingFunction animationEase = new ExponentialEase { EasingMode = EasingMode.EaseInOut, }; s_animationDuration = animationDuration; s_animationEase = animationEase; Initialize (ref animationDuration, ref animationEase); s_animationDuration = animationDuration; s_animationEase = animationEase; s_animationClock = new DoubleAnimation( 0 , 1 , s_animationDuration , FillBehavior.Stop ) .FreezeObject () ; }
/// <summary> /// Called when the <see cref="ExtendedVisualStateManager"/> transitions away from /// the element. /// The timeline which gets returned by this method is then used as a transitioning /// animation. /// </summary> /// <param name="fromTimeline"> /// The animation for which a visual transition timeline should be generated. /// The VisualStateManager wants to transition away from this timeline. /// By default, this can only be an animation of the same type as this class. /// </param> /// <param name="easingFunction"> /// An easing function to be applied to the resulting timeline. /// Can be null. /// </param> /// <returns> /// A <see cref="Timeline"/> which displays a visual transition away from this element. /// </returns> public virtual Timeline CreateFromTransitionTimeline(Timeline fromTimeline, IEasingFunction easingFunction) { // We want to animate FROM this animation to something else. // Use the fact that this animation supports automatic/dynamic values. ReadPreamble(); return((FromToByAnimationBase <T>)CreateInstance()); }
public static void HideUsingLinearAnimation( this UIElement element, int milliSeconds = 500, IEasingFunction easingFunction = null) { if (element == null) { return; } var anim = new DoubleAnimation() { From = 1, To = 0, Duration = new TimeSpan(0, 0, 0, 0, milliSeconds), }; if (easingFunction != null) { anim.EasingFunction = easingFunction; } anim.Completed += new EventHandler((sender, e) => { element.Visibility = Visibility.Collapsed; }); element.Opacity = 1; element.Visibility = Visibility.Visible; element.BeginAnimation(UIElement.OpacityProperty, anim); }
public static void Animate(this DependencyObject target, double?from, double?to, object propertyPath, int duration, int startTime, IEasingFunction easing = null, Action completed = null) { if (easing == null) { easing = new SineEase(); } var animation = new DoubleAnimation { To = to, From = @from, EasingFunction = easing, Duration = TimeSpan.FromMilliseconds(duration) }; Storyboard.SetTarget(animation, target); Storyboard.SetTargetProperty(animation, new PropertyPath(propertyPath)); var storyBoard = new Storyboard { BeginTime = TimeSpan.FromMilliseconds(startTime) }; if (completed != null) { storyBoard.Completed += (sender, args) => completed(); } storyBoard.Children.Add(animation); storyBoard.Begin(); }
public static DoubleAnimationUsingKeyFrames CreateAnim(this Storyboard sb, DependencyObject target, string propertyPath, IEasingFunction easing, double value, TimeSpan keyTime) { var doubleAnim = (from anim in sb.Children.OfType<DoubleAnimationUsingKeyFrames>() where GetSBExtTarget(anim) == target let prop = Storyboard.GetTargetProperty(anim) where prop.Path == propertyPath select anim).FirstOrDefault(); if (doubleAnim == null) { doubleAnim = new DoubleAnimationUsingKeyFrames(); SetSBExtTarget(doubleAnim, target); Storyboard.SetTarget(doubleAnim, target); Storyboard.SetTargetProperty(doubleAnim, new System.Windows.PropertyPath(propertyPath)); sb.Children.Add(doubleAnim); } EasingDoubleKeyFrame kf = new EasingDoubleKeyFrame(); kf.EasingFunction = easing; kf.KeyTime = keyTime; kf.Value = value; doubleAnim.KeyFrames.Add(kf); return doubleAnim; }
protected override Color GetCurrentValueCore(Color defaultOriginValue, Color defaultDestinationValue, AnimationClock animationClock) { System.Diagnostics.Debug.Assert(animationClock.CurrentState != ClockState.Stopped); if (!_isAnimationFunctionValid) { ValidateAnimationFunction(); } double progress = animationClock.CurrentProgress.Value; IEasingFunction easingFunction = EasingFunction; if (easingFunction != null) { progress = easingFunction.Ease(progress); } double fromVal = _keyvalues[0]; double toVal = _keyvalues[1]; double target; if (fromVal > toVal) { target = (1 - progress) * (fromVal - toVal) + toVal; } else { target = (toVal - fromVal) * progress + fromVal; } Color originColor = OriginColor; if (target == 0) { return(originColor); } return(ColorEx.ChangeColorBrightness(originColor, target)); }
public static async Task ThicknessAnimation( FrameworkElement element, Thickness to, Thickness from, Duration duration = new Duration(), PropertyPath propertyPath = null, IEasingFunction ease = null) { if (propertyPath == null) { propertyPath = new PropertyPath(FrameworkElement.MarginProperty); } //propertyPath ??= new PropertyPath(FrameworkElement.MarginProperty); var storyboard = new Storyboard(); var fadeAnimation = new ThicknessAnimation { From = from, To = to, Duration = !duration.HasTimeSpan ? new Duration(TimeSpan.FromSeconds(0.3)) : duration, EasingFunction = ease ?? new CircleEase() }; storyboard.Children.Add(fadeAnimation); Storyboard.SetTargetName(fadeAnimation, element.Name); Storyboard.SetTargetProperty(fadeAnimation, propertyPath); storyboard.Begin(element); await Task.Delay(fadeAnimation.Duration.TimeSpan); }
public LinearMatrixAnimation() { if (this.EasingFunction == null) { this.EasingFunction = new CubicEase(); } }
public Timeline CreateFromTransitionTimeline(Timeline fromTimeline, IEasingFunction easingFunction) { return(new PointAnimation() { EasingFunction = easingFunction }); }
public override object GetCurrentValue(object defaultOriginValue, object defaultDestinationValue, AnimationClock animationClock) { GridUnitType fromUnitType = ((GridLength)GetValue(GridLengthAnimation.FromProperty)).GridUnitType; GridUnitType toUnitType = ((GridLength)GetValue(GridLengthAnimation.ToProperty)).GridUnitType; double fromVal = ((GridLength)GetValue(GridLengthAnimation.FromProperty)).Value; double toVal = ((GridLength)GetValue(GridLengthAnimation.ToProperty)).Value; IEasingFunction easer = (IEasingFunction)GetValue(GridLengthAnimation.EasingFunctionProperty); if (fromVal > toVal) { if (easer == null) { return(new GridLength((1 - animationClock.CurrentProgress.Value) * (fromVal - toVal) + toVal, fromUnitType)); } else { return(new GridLength((1 - easer.Ease(animationClock.CurrentProgress.Value)) * (fromVal - toVal) + toVal, fromUnitType)); } } else { if (easer == null) { return(new GridLength(animationClock.CurrentProgress.Value * (toVal - fromVal) + fromVal, toUnitType)); } else { return(new GridLength(easer.Ease(animationClock.CurrentProgress.Value) * (toVal - fromVal) + fromVal, toUnitType)); } } }
private bool TransitionEffectAwareGoToStateCore(FrameworkElement control, FrameworkElement stateGroupsRoot, string stateName, VisualStateGroup group, VisualState state, bool useTransitions, VisualTransition transition, bool animateWithTransitionEffect, VisualState previousState) { IEasingFunction generatedEasingFunction = null; if (animateWithTransitionEffect) { generatedEasingFunction = transition.GeneratedEasingFunction; var function2 = new DummyEasingFunction { DummyValue = FinishesWithZeroOpacity(control, stateGroupsRoot, state, previousState) ? 0.01 : 0.0 }; transition.GeneratedEasingFunction = function2; } var flag = base.GoToStateCore(control, stateGroupsRoot, stateName, group, state, useTransitions); if (animateWithTransitionEffect) { transition.GeneratedEasingFunction = generatedEasingFunction; if (flag) { AnimateTransitionEffect(stateGroupsRoot, transition); } } SetCurrentState(group, state); return(flag); }
/// <summary> /// Starts animating a dependency property of a framework element to a /// target value. /// </summary> /// <param name="target">The element to animate.</param> /// <param name="animatingDependencyProperty">The dependency property to /// animate.</param> /// <param name="propertyPath">The path of the dependency property to /// animate.</param> /// <param name="targetValue">The value to animate the dependency /// property to.</param> /// <param name="timeSpan">The duration of the animation.</param> /// <param name="easingFunction">The easing function to uses to /// transition the data points.</param> public static void BeginAnimation( this FrameworkElement target, DependencyProperty animatingDependencyProperty, string propertyPath, object targetValue, TimeSpan timeSpan, IEasingFunction easingFunction) { Storyboard storyBoard = target.Resources[GetStoryboardKey(propertyPath)] as Storyboard; if (storyBoard != null) { storyBoard.Stop(); target.Resources.Remove(GetStoryboardKey(propertyPath)); } storyBoard = CreateStoryboard(target, animatingDependencyProperty, propertyPath, ref targetValue, timeSpan, easingFunction); storyBoard.Completed += (source, args) => { storyBoard.Stop(); target.SetValue(animatingDependencyProperty, targetValue); target.Resources.Remove(GetStoryboardKey(propertyPath)); }; target.Resources.Add(GetStoryboardKey(propertyPath), storyBoard); storyBoard.Begin(); }
public static void Animate(this DependencyObject target, double? from, double? to, object propertyPath, int duration, int startTime, IEasingFunction easing = null, Action completed = null) { if (easing == null) easing = new SineEase(); var animation = new DoubleAnimation { To = to, From = @from, EasingFunction = easing, Duration = TimeSpan.FromMilliseconds(duration) }; Storyboard.SetTarget(animation, target); Storyboard.SetTargetProperty(animation, new PropertyPath(propertyPath)); var storyBoard = new Storyboard {BeginTime = TimeSpan.FromMilliseconds(startTime)}; if (completed != null) storyBoard.Completed += (sender, args) => completed(); storyBoard.Children.Add(animation); storyBoard.Begin(); }
/// /// <summary> /// Helper to create double animation</summary> /// public static Storyboard AddDouble( this Storyboard sb, int durationMs, DependencyObject element, PropertyPath path, double from, double to, IEasingFunction easing = null ) { DoubleAnimation da; da = new DoubleAnimation(); da.Duration = new Duration(TimeSpan.FromMilliseconds(durationMs)); da.From = from; da.To = to; if (easing != null) { da.EasingFunction = easing; } Storyboard.SetTarget(da, element); Storyboard.SetTargetProperty(da, path); sb.Children.Add(da); return sb; }
private Menu() { InitializeComponent(); goUpDownAnimation = ((Storyboard)MainWindow.Instance.Resources["ResizeAnimation"]).Clone(); ChangeKeyTimeOfAllKeyFrames(goUpDownAnimation, (KeyTime)Application.Current.Resources["AnimationKeyTime"]); IEasingFunction goUpDownAnimationEasingFunction = (IEasingFunction)Application.Current.Resources["AnimationEasingFunction"]; foreach (IKeyFrameAnimation animation in goUpDownAnimation.Children) { ((EasingDoubleKeyFrame)animation.KeyFrames[0]).EasingFunction = goUpDownAnimationEasingFunction; } goUpDownWindowResizeAnimationAddition = (ParallelTimeline)Resources["GoUpDownWindowResizeAnimationAddition"]; goUpDownAnimation.Children.Add(goUpDownWindowResizeAnimationAddition); flyAnimation = ((Storyboard)MainWindow.Instance.Resources["ResizeAnimation"]).Clone(); ChangeKeyTimeOfAllKeyFrames(flyAnimation, (KeyTime)Resources["FlyKeyTime"]); flyAnimation.Children.Add((ParallelTimeline)Resources["FlyWindowResizeAnimationAddition"]); void ChangeKeyTimeOfAllKeyFrames(TimelineGroup timelineGroup, KeyTime keyTime) { foreach (IKeyFrameAnimation animation in timelineGroup.Children) { ((IKeyFrame)animation.KeyFrames[0]).KeyTime = keyTime; } } }
public static void ShowUsingLinearAnimation( this UIElement element, int milliSeconds = 500, IEasingFunction easingFunction = null) { if (element == null) { return; } var anim = new DoubleAnimation() { From = 0, To = 1, Duration = new TimeSpan(0, 0, 0, 0, milliSeconds) }; if (easingFunction != null) { anim.EasingFunction = easingFunction; } element.Opacity = 0; element.Visibility = Visibility.Visible; element.BeginAnimation(UIElement.OpacityProperty, anim); }
/// <summary> /// Animates the grid let set /// </summary> /// <param name="defaultOriginValue">The original value to animate</param> /// <param name="defaultDestinationValue">The final value</param> /// <param name="animationClock">The animation clock (timer)</param> /// <returns>Returns the new grid length to set</returns> public override object GetCurrentValue(object defaultOriginValue, object defaultDestinationValue, AnimationClock animationClock) { double fromVal = ((GridLength)GetValue(FromProperty)).Value; double toVal = ((GridLength)GetValue(ToProperty)).Value; //check that from was set from the caller //if (fromVal == 1) // //set the from as the actual value // fromVal = ((GridLength)defaultDestinationValue).Value; double progress = animationClock.CurrentProgress.Value; IEasingFunction easingFunction = EasingFunction; if (easingFunction != null) { progress = easingFunction.Ease(progress); } if (fromVal > toVal) { return(new GridLength((1 - progress) * (fromVal - toVal) + toVal, GridUnitType.Pixel)); } return(new GridLength(progress * (toVal - fromVal) + fromVal, GridUnitType.Pixel)); }
public static void Animate(this DependencyObject target, double from, double to, object propertyPath, int duration, int startTime, IEasingFunction easing = null, Action completed = null) { if (easing == null) easing = new SineEase(); var db = new DoubleAnimation(); db.To = to; db.From = from; db.EasingFunction = easing; db.Duration = TimeSpan.FromMilliseconds(duration); Storyboard.SetTarget(db, target); Storyboard.SetTargetProperty(db, new PropertyPath(propertyPath)); var sb = new Storyboard(); sb.BeginTime = TimeSpan.FromMilliseconds(startTime); if (completed != null) { sb.Completed += (s, e) => completed(); } sb.Children.Add(db); sb.Begin(); }
void listener_Flick(object sender, FlickGestureEventArgs e) { //Debug.WriteLine("listener_Flick"); if (e.Direction == Orientation.Vertical) { _state = State.Flicking; _selectedItem = null; if (!IsExpanded) { IsExpanded = true; } Point velocity = new Point(0, e.VerticalVelocity); double flickDuration = PhysicsConstants.GetStopTime(velocity); Point flickEndPoint = PhysicsConstants.GetStopPoint(velocity); IEasingFunction flickEase = PhysicsConstants.GetEasingFunction(flickDuration); AnimatePanel(new Duration(TimeSpan.FromSeconds(flickDuration)), flickEase, _panningTransform.Y + flickEndPoint.Y); e.Handled = true; _selectedItem = null; UpdateItemState(); } }
/// /// <summary> /// Helper to create double animation</summary> /// public static Storyboard AddDouble( this Storyboard sb, int durationMs, DependencyObject element, PropertyPath path, double from, double to, IEasingFunction easing = null ) { DoubleAnimation da; da = new DoubleAnimation(); da.Duration = new Duration(TimeSpan.FromMilliseconds(durationMs)); da.From = from; da.To = to; if (easing != null) { da.EasingFunction = easing; } Storyboard.SetTarget(da, element); Storyboard.SetTargetProperty(da, path); sb.Children.Add(da); return(sb); }
/// <summary> /// Creates a new EasingThicknessKeyFrame. /// </summary> public EasingThicknessKeyFrame(Thickness value, KeyTime keyTime, IEasingFunction easingFunction) : this() { Value = value; KeyTime = keyTime; EasingFunction = easingFunction; }
/// <summary> /// Animates the translate transform object, responsible for displacement of the target. /// </summary> /// <param name="target">The target object.</param> /// <param name="storyboard">The storyboard.</param> /// <param name="to">Animation's ending value.</param> /// <param name="seconds">Duration of the animation in seconds.</param> /// <param name="easingFunction">Easing function applied to the animation.</param> public static void AnimateTranslateTransform(this DependencyObject target, Storyboard storyboard, Point to, double seconds, IEasingFunction easingFunction = null) { Duration duration = new Duration(TimeSpan.FromSeconds(seconds)); DoubleAnimation doubleAnimationX = new DoubleAnimation() { To = to.X, Duration = duration, EasingFunction = easingFunction }; DoubleAnimation doubleAnimationY = new DoubleAnimation() { To = to.Y, Duration = duration, EasingFunction = easingFunction }; storyboard.Stop(); storyboard.Children.Clear(); storyboard.Duration = duration; storyboard.Children.Add(doubleAnimationX); storyboard.Children.Add(doubleAnimationY); Storyboard.SetTarget(doubleAnimationX, target); Storyboard.SetTarget(doubleAnimationY, target); Storyboard.SetTargetProperty(doubleAnimationX, (target as UIElement).GetPropertyPathForTranslateTransformX()); Storyboard.SetTargetProperty(doubleAnimationY, (target as UIElement).GetPropertyPathForTranslateTransformY()); storyboard.Begin(); }
/// <summary> /// Animates specified property of the object. /// </summary> /// <param name="target">The target object to animate.</param> /// <param name="propertyPath">Property path, e.g. Canvas.Top.</param> /// <param name="from">Animation's starting value.</param> /// <param name="to">Animation's ending value.</param> /// <param name="milliseconds">Duration of the animation in milliseconds.</param> /// <param name="easingFunction">Easing function applied to the animation.</param> /// <param name="completed">Event handler called when animation completed.</param> /// <returns>Returns started storyboard.</returns> public static Storyboard AnimateDoubleProperty(this DependencyObject target, string propertyPath, double? from, double? to, double milliseconds, IEasingFunction easingFunction = null, EventHandler completed = null) { Duration duration = new Duration(TimeSpan.FromMilliseconds(milliseconds)); DoubleAnimation doubleAnimation = new DoubleAnimation() { From = from, To = to, Duration = duration, EasingFunction = easingFunction }; Storyboard storyboard = new Storyboard(); storyboard.Duration = duration; storyboard.Children.Add(doubleAnimation); Storyboard.SetTarget(doubleAnimation, target); Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath(propertyPath)); if (completed != null) storyboard.Completed += completed; storyboard.Begin(); return storyboard; }
/// <summary> /// Animates specified property of the object. /// </summary> /// <param name="target">The target object to animate.</param> /// <param name="propertyPath">Property path, e.g. Canvas.Top.</param> /// <param name="from">Animation's starting value.</param> /// <param name="to">Animation's ending value.</param> /// <param name="milliseconds">Duration of the animation in milliseconds.</param> /// <param name="easingFunction">Easing function applied to the animation.</param> /// <param name="completed">Event handler called when animation completed.</param> /// <returns>Returns started storyboard.</returns> public static Storyboard AnimateDoubleProperty(this DependencyObject target, string propertyPath, double?from, double?to, double milliseconds, IEasingFunction easingFunction = null, EventHandler completed = null) { Duration duration = new Duration(TimeSpan.FromMilliseconds(milliseconds)); DoubleAnimation doubleAnimation = new DoubleAnimation() { From = from, To = to, Duration = duration, EasingFunction = easingFunction }; Storyboard storyboard = new Storyboard(); storyboard.Duration = duration; storyboard.Children.Add(doubleAnimation); Storyboard.SetTarget(doubleAnimation, target); Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath(propertyPath)); if (completed != null) { storyboard.Completed += completed; } storyboard.Begin(); return(storyboard); }
public void InstanceMoveFromTo(FrameworkElement cell, double from_x, double from_y, double to_x, double to_y, TimeSpan duration, IEasingFunction easing = null, Action <FrameworkElement> completed = null) { TransformGroup transformGroup = cell.RenderTransform as TransformGroup; TranslateTransform translateTransform = null; foreach (Transform item in transformGroup.Children) { if (item is TranslateTransform) { translateTransform = item as TranslateTransform; break; } } if (translateTransform == null) { translateTransform = new TranslateTransform(); transformGroup.Children.Add(translateTransform); } this.Animate(cell, from_x, from_y, to_x, to_y, duration, easing, completed); }
public static Storyboard GetAnimation(AnimationDirection? animationDirection, bool isInAnimation, int animationTimeMS, IEasingFunction easingFunction = null) { var xAxis = "RenderTransform.(TranslateTransform.X)"; var yAxis = "RenderTransform.(TranslateTransform.Y)"; var easing = easingFunction != null ? easingFunction : new QuadraticEase(); var opac = GetOpac(isInAnimation, animationTimeMS); var story = new Storyboard(); (story as IAddChild).AddChild(opac); DoubleAnimation anim = null; if (animationDirection != null) { if (isInAnimation) { anim = new DoubleAnimation(animationDirection == AnimationDirection.Left || animationDirection == AnimationDirection.Top ? -30 : 30, 0, new Duration(new TimeSpan(0, 0, 0, 0, animationTimeMS))) { EasingFunction = easing }; } else { anim = new DoubleAnimation(0, animationDirection == AnimationDirection.Left || animationDirection == AnimationDirection.Top ? -30 : 30, new Duration(new TimeSpan(0, 0, 0, 0, animationTimeMS))) { EasingFunction = easing }; } if (anim != null) { anim.SetValue(Storyboard.TargetPropertyProperty, new PropertyPath(animationDirection == AnimationDirection.Left || animationDirection == AnimationDirection.Right ? xAxis : yAxis)); (story as IAddChild).AddChild(anim); } } return story; }
/// <summary> /// Updates the easing function of the double animation. /// </summary> /// <param name="ease">The easing funciton, if any, to use.</param> public void UpdateEasingFunction(IEasingFunction ease) { if (_daRunning != null && _daRunning.EasingFunction != ease) { _daRunning.EasingFunction = ease; } }
/// <summary> /// Double 애니메이션을 실행합니다. /// </summary> /// <param name="animatable"></param> /// <param name="property"></param> /// <param name="toValue"></param> /// <param name="duration"></param> /// <param name="easing"></param> /// <param name="completedEvent"></param> public static void BeginDoubleAnimation( this Animatable animatable, DependencyProperty property, double toValue, double duration = 400, IEasingFunction easing = null, EventHandler completedEvent = null) { double fromValue = (double)animatable.GetValue(property); var animation = new DoubleAnimation() { To = toValue, Duration = TimeSpan.FromMilliseconds(duration), EasingFunction = easing, FillBehavior = FillBehavior.HoldEnd }; if (completedEvent != null) { animation.Completed += completedEvent; } animatable.BeginAnimation(property, animation); }
private void AnimatePanel(Duration duration, IEasingFunction ease, double to) { // Be sure not to run past the first or last items double newTo = Math.Max(_minimumPanelScroll, Math.Min(_maximumPanelScroll, to)); if (to != newTo) { // Adjust the duration double originalDelta = Math.Abs(_panningTransform.Y - to); double modifiedDelta = Math.Abs(_panningTransform.Y - newTo); double factor = modifiedDelta / originalDelta; duration = new Duration(TimeSpan.FromMilliseconds(duration.TimeSpan.Milliseconds * factor)); to = newTo; } double from = _panningTransform.Y; StopAnimation(); CompositionTarget.Rendering += AnimationPerFrameCallback; _panelAnimation.Duration = duration; _panelAnimation.EasingFunction = ease; _panelAnimation.From = from; _panelAnimation.To = to; _panelStoryboard.Begin(); _panelStoryboard.SeekAlignedToLastTick(TimeSpan.Zero); _isAnimating = true; }
public static void animate(this IAnimatable i, DependencyProperty dp, int ms, double to, int skewms = 0, IEasingFunction easing = null, EventHandler onCompleted = null, double?by = null, double?from = null) { var timeline = new DoubleAnimation(to, new Duration(TimeSpan.FromMilliseconds(ms))) { BeginTime = TimeSpan.FromMilliseconds(skewms), EasingFunction = easing }; if (onCompleted != null) { timeline.Completed += onCompleted; } if (by != null) { timeline.By = by; } if (from != null) { timeline.From = from; } i.BeginAnimation(dp, timeline); }
public static void Animate(this DependencyObject target, double?from, double to, object propertyPath, int duration, int startTime, IEasingFunction easing = null, Action completed = null) { if (easing == null) { easing = new SineEase(); } if (target != null) { var db = new DoubleAnimation(); db.To = to; db.From = from; db.EasingFunction = easing; db.Duration = TimeSpan.FromMilliseconds(duration); Storyboard.SetTarget(db, target); Storyboard.SetTargetProperty(db, new PropertyPath(propertyPath)); var sb = new Storyboard(); sb.BeginTime = TimeSpan.FromMilliseconds(startTime); if (completed != null) { sb.Completed += (s, e) => completed(); } sb.Children.Add(db); sb.Begin(); } }
public static void BeginAnimation(ChartArea seriesHost, string propertyName, object currentValue, object targetValue, Action<object, object> propertyUpdateAction, Dictionary<string, StoryboardInfo> storyboards, TimeSpan timeSpan, IEasingFunction easingFunction) { if (timeSpan == TimeSpan.Zero) propertyUpdateAction(currentValue, targetValue); else DependencyPropertyAnimationHelper.CreateAnimation(seriesHost, propertyName, currentValue, targetValue, propertyUpdateAction, storyboards, timeSpan, easingFunction).Begin(); }
protected void OnDisabled(bool useTransitions = true, IEasingFunction ease = null) { this.EnabledStatus = Primitives.EnabledStatus.Disabled; OnDisabledOverride(useTransitions, ease); SendOnDisabled(); }
/// <summary> /// Creates a new EasingByteKeyFrame. /// </summary> public EasingByteKeyFrame(Byte value, KeyTime keyTime, IEasingFunction easingFunction) : this() { Value = value; KeyTime = keyTime; EasingFunction = easingFunction; }
protected void OnDeactivated(bool useTransitions = true, IEasingFunction ease = null) { this.ActivationStatus = ActivationStatus.Inactive; OnDeactivatedOverride(useTransitions, ease); SendOnDeactivated(); }
public override Vector2 Interpolate(Vector2 start, double keyframe) { if (keyframe <= 0.0) { return(start); } if (keyframe >= 1.0) { return(Value); } if (double.IsNaN(keyframe)) { return(start); } IEasingFunction easingFunction = EasingFunction; if (easingFunction != null) { keyframe = easingFunction.Ease(keyframe); } double x = (start.X + ((Value.X - start.X) * keyframe)); double y = (start.Y + ((Value.Y - start.Y) * keyframe)); return(new Vector2((float)x, (float)y)); }
public static Storyboard CreateAnimation(this DependencyObject target, Dictionary<string, StoryboardInfo> storyboards, DependencyProperty animatingDependencyProperty, string propertyPath, string propertyKey, object initialValue, object targetValue, TimeSpan timeSpan, IEasingFunction easingFunction, Action releaseAction) { StoryboardInfo storyboardInfo; storyboards.TryGetValue(DependencyPropertyAnimationHelper.GetStoryboardKey(propertyKey), out storyboardInfo); if (storyboardInfo != null) { DependencyObject storyboardTarget = storyboardInfo.StoryboardTarget; storyboardInfo.Storyboard.Stop(); storyboards.Remove(DependencyPropertyAnimationHelper.GetStoryboardKey(propertyKey)); if (storyboardInfo.ReleaseAction != null) { storyboardInfo.ReleaseAction(); storyboardInfo.ReleaseAction = (Action)null; } } storyboardInfo = new StoryboardInfo(); storyboardInfo.Storyboard = DependencyPropertyAnimationHelper.CreateStoryboard(target, animatingDependencyProperty, propertyPath, propertyKey, ref targetValue, timeSpan, easingFunction); storyboardInfo.ReleaseAction = releaseAction; storyboardInfo.StoryboardTarget = target; storyboardInfo.AnimateFrom = initialValue; storyboardInfo.Storyboard.Completed += (EventHandler)((source, args) => { storyboards.Remove(DependencyPropertyAnimationHelper.GetStoryboardKey(propertyKey)); if (storyboardInfo.ReleaseAction == null) return; storyboardInfo.ReleaseAction(); storyboardInfo.ReleaseAction = (Action)null; }); storyboards.Add(DependencyPropertyAnimationHelper.GetStoryboardKey(propertyKey), storyboardInfo); return storyboardInfo.Storyboard; }
public void Animate(double Before, double After, double Duration, IEasingFunction Easing, DependencyProperty Property, FrameworkElement Item) { Cancel = false; IsCompleted = false; if (Duration == 0 || Before == After) { Item.SetValue(Property, After); return; } this.Before = Before; Item.SetValue(Property, Before); af = After; dp = Property; cnr = Item; Storyboard sb = new Storyboard(); DoubleAnimation da = new DoubleAnimation() { From = Before, To = After, Duration = TimeSpan.FromMilliseconds(Duration), FillBehavior = FillBehavior.Stop, EasingFunction = Easing }; Storyboard.SetTargetProperty(da, new PropertyPath(Property)); sb.Children.Add(da); sb.Completed += Sb_Completed; Item.BeginStoryboard(sb); }
public RangeAnimation(Range from, Range to, Duration duration, FillBehavior fillBehavior = FillBehavior.Stop, IEasingFunction easingFunction = null) { From = from; To = to; Duration = duration; FillBehavior = fillBehavior; EasingFunction = easingFunction; }
public static DoubleAnimation CreateDoubleAnimation(string targetName, DependencyProperty targetProperty, double toValue, double fromValue = 0.0, TimeSpan? beginTimeSpan = null, TimeSpan? durationSpan = null, IEasingFunction easingFuction = null) { var animation = CreateDoubleAnimation(toValue, fromValue, beginTimeSpan, durationSpan, easingFuction); Storyboard.SetTargetName(animation, targetName); Storyboard.SetTargetProperty(animation, new PropertyPath(targetProperty)); return animation; }
public AnimationInfo(DependencyObject target, PropertyPath propertyPath, double startValue, double endValue, IEasingFunction easingFunction = null) { Target = target; PropertyPath = propertyPath; StartValue = startValue; EndValue = endValue; EasingFunction = easingFunction; }
public static DoubleAnimation CreateAnimation(double from, double to, double beginTime, double time, IEasingFunction ease = null, EventHandler completed = null) { DoubleAnimation animation = new DoubleAnimation(from, to, new Duration(TimeSpan.FromSeconds(time))); animation.BeginTime = TimeSpan.FromSeconds(beginTime); if (ease != null) animation.EasingFunction = ease; if (completed != null) animation.Completed += completed; animation.Freeze(); return animation; }
//public static DoubleAnimation TranslateYOnNavigateIn() //{ // return TranslateY(250, 350, 0, new ExponentialEase() { EasingMode = EasingMode.EaseOut, Exponent = 4 }); //} //public static DoubleAnimation ChangeOpacityOnNavigateIn() //{ // return ChangeOpacity(0, 250, 1, new ExponentialEase() { EasingMode = EasingMode.EaseOut }); //} private static DoubleAnimation GetGenericAnimation(double from, double to, int millis, IEasingFunction easingFunction) { DoubleAnimation d = new DoubleAnimation(); d.EasingFunction = easingFunction; d.Duration = TimeSpan.FromMilliseconds(millis); d.From = from; d.To = to; return d; }
public MarginTween(FrameworkElement target, Thickness startValue, Thickness endValue, Duration duration, IEasingFunction easingFunction) : this() { StartMargin = startValue; EndMargin = endValue; Target = target; Duration = duration; EasingFunction = easingFunction; }
/* public void GoTo(double targetOpacity, Duration duration, IEasingFunction easingFunction) { GoTo(targetOpacity, duration, easingFunction, null); }*/ public void GoTo(double targetOpacity, Duration duration, IEasingFunction easingFunction, Action completionAction) { _daRunning.To = targetOpacity; _daRunning.Duration = duration; _daRunning.EasingFunction = easingFunction; _sbRunning.Begin(); _suppressChangeNotification = true; _sbRunning.SeekAlignedToLastTick(TimeSpan.Zero); _oneTimeAction = completionAction; }
private static DoubleAnimation CreateDoubleAnimation(double fromValue, double toValue, double seconds, IEasingFunction easing) { var animation = new DoubleAnimation { From = fromValue, To = toValue, Duration = new Duration(TimeSpan.FromSeconds(seconds)), }; return animation; }
/// <summary> /// 创建UI的Storyboard动画的子对象PointAnimation /// </summary> public static PointAnimation CreatePointAnimation(DependencyObject d, string propertyName, Point to, Duration duration, IEasingFunction easingFunction) { PointAnimation pointAnimation = new PointAnimation() { To = to, Duration = duration, EasingFunction = easingFunction }; Storyboard.SetTarget(pointAnimation, d); Storyboard.SetTargetProperty(pointAnimation, new PropertyPath(propertyName)); return pointAnimation; }
/// <summary> /// 创建UI的Storyboard动画的子对象DoubleAnimation /// </summary> public static DoubleAnimation CreateDoubleAnimation(DependencyObject d, string propertyName, double to, Duration duration, IEasingFunction easingFunction) { DoubleAnimation doubleAnimation = new DoubleAnimation() { To = to, Duration = duration, EasingFunction = easingFunction }; Storyboard.SetTarget(doubleAnimation, d); Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath(propertyName)); return doubleAnimation; }
public static Storyboard CreateAnimation(ChartArea seriesHost, string propertyName, object currentValue, object targetValue, Action<object, object> propertyUpdateAction, Dictionary<string, StoryboardInfo> storyboards, TimeSpan timeSpan, IEasingFunction easingFunction) { ObjectPool<PropertyAnimator, object> propertyAnimatorPool = (ObjectPool<PropertyAnimator, object>)seriesHost.SingletonRegistry.GetSingleton((object)"__PropertyAnimatorPool__", (Func<object>)(() => (object)new ObjectPool<PropertyAnimator, object>((Func<PropertyAnimator>)(() => new PropertyAnimator()), (Action<PropertyAnimator, object>)((obj, context) => obj.AnimatedValue = context), (Action<PropertyAnimator>)(obj => obj.UpdateAction = (Action<object, object>)null))), (Action<object>)(obj => ((ObjectPool<PropertyAnimator, object>)obj).ReleaseAll())); PropertyAnimator propertyAnimator = propertyAnimatorPool.Get(currentValue); propertyAnimator.UpdateAction = propertyUpdateAction; Action releaseAction = (Action)(() => { propertyAnimatorPool.Release(propertyAnimator); propertyAnimatorPool.AdjustPoolSize(); }); return DependencyPropertyAnimationHelper.CreateAnimation((DependencyObject)propertyAnimator, storyboards, PropertyAnimator.AnimatedValueProperty, "AnimatedValue", propertyName, currentValue, targetValue, timeSpan, easingFunction, releaseAction); }
public static DoubleAnimation CreateDoubleAnimation(double from, double to, IEasingFunction easing, DependencyObject target, object propertyPath, TimeSpan duration) { var db = new DoubleAnimation(); db.To = to; db.From = from; db.EasingFunction = easing; db.Duration = duration; Storyboard.SetTarget(db, target); Storyboard.SetTargetProperty(db, new PropertyPath(propertyPath)); return db; }
public DLMatrixAnimation(Matrix fromValue, Matrix toValue, Duration duration, Action<object> frameCallback, IEasingFunction easingFunction = null) { FrameCallback = frameCallback; _matrixTransform = new MatrixTransform(); _matrixAnimation = new MatrixAnimation(fromValue, toValue, duration); if(easingFunction != null) { _matrixAnimation.EasingFunction = easingFunction; } _matrixAnimation.Completed += (sender, args) => { FrameCallback(_matrixAnimation.To); _matrixTransform.BeginAnimation(MatrixTransform.MatrixProperty, null); }; }
public DLRectAnimation(Rect fromValue, Rect toValue, Duration duration, Action<object> frameCallback, IEasingFunction easingFunction = null) { FrameCallback = frameCallback; _areaRect = new AreaRect(); _rectAnimation = new System.Windows.Media.Animation.RectAnimation(fromValue, toValue, duration); if(easingFunction != null) { _rectAnimation.EasingFunction = easingFunction; } _rectAnimation.Completed += (sender, args) => { FrameCallback(_rectAnimation.To); _areaRect.BeginAnimation(AreaRect.AreaRectProperty, null); }; }
public DLPointAnimation(Point fromValue, Point toValue, Duration duration, Action<object> frameCallback, IEasingFunction easingFunction = null) { FrameCallback = frameCallback; _point = new AnimationPoint(); _pointAnimation = new PointAnimation(fromValue, toValue, duration); if (easingFunction != null) { _pointAnimation.EasingFunction = easingFunction; } _pointAnimation.Completed += (sender, args) => { FrameCallback(_pointAnimation.To); _point.BeginAnimation(AnimationPoint.PointProperty, null); }; }
private static List<double> CalculateEaseValues(double range, int count, IEasingFunction easingFunction, double baseValue = 0d) { var items = new List<double>(); var easePhase = 1d / count; for (var i = 0; i < count; i++) { var valueToEase = easePhase * i; var easeValue = easingFunction.Ease(valueToEase); items.Add(baseValue + (easeValue * range)); } return items; }
public static DoubleAnimation CreateDoubleAnimation(double toValue, double fromValue = 0.0, TimeSpan? beginTimeSpan = null, TimeSpan? durationSpan = null, IEasingFunction easingFuction = null) { var duration = durationSpan != null ? new Duration(durationSpan.Value) : new Duration(TimeSpan.FromSeconds(0)); beginTimeSpan = beginTimeSpan != null ? beginTimeSpan.Value : TimeSpan.FromSeconds(0); var animation = new DoubleAnimation { BeginTime = beginTimeSpan, From = fromValue, To = toValue, Duration = duration, EasingFunction = easingFuction, }; return animation; }
public static ThicknessAnimation CreateThicknessAnimation(Thickness toValue, Thickness? fromValue = null, TimeSpan? beginTimeSpan = null, TimeSpan? durationSpan = null, IEasingFunction easingFuction = null) { var duration = durationSpan != null ? new Duration(durationSpan.Value) : new Duration(TimeSpan.FromSeconds(0)); beginTimeSpan = beginTimeSpan != null ? beginTimeSpan.Value : TimeSpan.FromSeconds(0); fromValue = fromValue ?? new Thickness(0); var animation = new ThicknessAnimation() { BeginTime = beginTimeSpan, From = fromValue, To = toValue, Duration = duration, EasingFunction = easingFuction }; return animation; }