public static Storyboard OpacityAnimation(this UIElement element, double beginTimeInSeconds, double durationInSeconds, double fromOpacity, double toOpacity , EasingFunctionBase easingFunction = null, Storyboard sb = null, RepeatBehavior? repeatBehavior = null, bool autoReverse = false) { if (sb == null) sb = new Storyboard(); Storyboard.SetTarget(sb, element); DoubleAnimation opacityAnim = new DoubleAnimation(); opacityAnim.BeginTime = TimeSpan.FromSeconds(beginTimeInSeconds); opacityAnim.From = fromOpacity; opacityAnim.To = toOpacity; opacityAnim.EasingFunction = easingFunction; Storyboard.SetTargetProperty(opacityAnim, new PropertyPath(UIElement.OpacityProperty)); Storyboard.SetTarget(opacityAnim, element); if (repeatBehavior.HasValue) { opacityAnim.RepeatBehavior = repeatBehavior.Value; } sb.AutoReverse = autoReverse; sb.Children.Add(opacityAnim); return sb; }
public static Storyboard WidthHeightAnimation(this FrameworkElement element, double beginTimeInSeconds, double durationInSeconds, double fromWidth, double fromHeight, double toWidth, double toHeight, EasingFunctionBase easingFunction = null) { Storyboard sb = new Storyboard(); Storyboard.SetTarget(sb, element); DoubleAnimationUsingKeyFrames widthAnim = new DoubleAnimationUsingKeyFrames(); DoubleAnimationUsingKeyFrames heightAnim = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTargetProperty(widthAnim, new PropertyPath(FrameworkElement.WidthProperty)); Storyboard.SetTargetProperty(heightAnim, new PropertyPath(FrameworkElement.HeightProperty)); widthAnim.BeginTime = heightAnim.BeginTime = TimeSpan.FromSeconds(beginTimeInSeconds); widthAnim.KeyFrames.Add(new AnimationKeyFrame(fromWidth, 0, easingFunction)); widthAnim.KeyFrames.Add(new AnimationKeyFrame(toWidth, durationInSeconds, easingFunction)); heightAnim.KeyFrames.Add(new AnimationKeyFrame(fromHeight, 0, easingFunction)); heightAnim.KeyFrames.Add(new AnimationKeyFrame(toHeight, durationInSeconds, easingFunction)); sb.Children.Add(widthAnim); sb.Children.Add(heightAnim); return sb; }
public void Draw(EasingFunctionBase easingFunction) { canvas1.Children.Clear(); PathSegmentCollection pathSegments = new PathSegmentCollection(); for (double i = 0; i < 1; i += _samplingInterval) { double x = i * canvas1.Width; double y = easingFunction.Ease(i) * canvas1.Height; var segment = new LineSegment(); segment.Point = new Point(x, y); pathSegments.Add(segment); } var p = new Path(); p.Stroke = new SolidColorBrush(Colors.Black); p.StrokeThickness = 3; PathFigureCollection figures = new PathFigureCollection(); figures.Add(new PathFigure() { Segments = pathSegments }); p.Data = new PathGeometry() { Figures = figures }; canvas1.Children.Add(p); }
public RotateEffect(double from, double to, double speed, EasingMode mode, EasingFunctionBase easingFunction) { this.From = from; this.To = to; this.Speed = speed; this.Mode = mode; this.EasingFunction = easingFunction; }
public MoveEffect(Point from, Point to, double speed,int duration,EasingMode mode,EasingFunctionBase easingFunction) { this.From = from; this.To = to; this.Speed = speed; this.Duration = duration; this.Mode = mode; this.EasingFunction = easingFunction; }
public OpacityEffect(double from, double to, double speed,int duration,EasingMode mode,EasingFunctionBase easingFunction) { this.From = from; this.To = to; this.Speed = speed; this.Duration = duration; this.Mode = mode; this.EasingFunction = easingFunction; }
/// <summary> /// Creates the storyboard for animating a child from its old location to the new location. /// The Translation and Scale properties are animated. /// </summary> /// <param name="element">UIElement for which the storyboard has to be created</param> /// <param name="newLocation">New location of the UIElement</param> /// <param name="period">Duration of animation</param> /// <param name="easing">Easing function</param> /// <returns>Storyboard</returns> internal Storyboard CreateTransition(UIElement element, Point newLocation, TimeSpan period, EasingFunctionBase easing) { Duration duration = new Duration(period); // Animate X DoubleAnimation translateAnimationX = new DoubleAnimation(); translateAnimationX.To = newLocation.X; translateAnimationX.Duration = duration; if (easing != null) translateAnimationX.EasingFunction = easing; Storyboard.SetTarget(translateAnimationX, element); Storyboard.SetTargetProperty(translateAnimationX, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[1].(TranslateTransform.X)")); // Animate Y DoubleAnimation translateAnimationY = new DoubleAnimation(); translateAnimationY.To = newLocation.Y; translateAnimationY.Duration = duration; if (easing != null) translateAnimationY.EasingFunction = easing; Storyboard.SetTarget(translateAnimationY, element); Storyboard.SetTargetProperty(translateAnimationY, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[1].(TranslateTransform.Y)")); // Animate ScaleX DoubleAnimation scaleAnimationX = new DoubleAnimation(); scaleAnimationX.To = 1.0D; scaleAnimationX.Duration = duration; if (easing != null) scaleAnimationX.EasingFunction = easing; Storyboard.SetTarget(scaleAnimationX, element); Storyboard.SetTargetProperty(scaleAnimationX, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)")); // Animate ScaleY DoubleAnimation scaleAnimationY = new DoubleAnimation(); scaleAnimationY.To = 1.0D; scaleAnimationY.Duration = duration; if (easing != null) scaleAnimationY.EasingFunction = easing; Storyboard.SetTarget(scaleAnimationY, element); Storyboard.SetTargetProperty(scaleAnimationY, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)")); Storyboard sb = new Storyboard(); sb.Duration = duration; sb.Children.Add(translateAnimationX); sb.Children.Add(translateAnimationY); sb.Children.Add(scaleAnimationX); sb.Children.Add(scaleAnimationY); return sb; }
/// <summary> /// 返回根据ProtertyPath封装过的DoubleAnimation /// </summary> /// <param name="PropertyPath">属性路径</param> /// <param name="seconds">动画时间</param> /// <param name="from">起始值</param> /// <param name="to">结束值</param> /// <param name="EasingFun">缓动函数</param> /// <returns>已组装过的DoubleAnimation</returns> public static DoubleAnimation GetDoubleAnimation(string PropertyPath, double seconds, double from, double to, EasingFunctionBase EasingFun) { DoubleAnimation _doubleAnimation = new DoubleAnimation(); _doubleAnimation.From = from; _doubleAnimation.To = to; _doubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(seconds)); if (EasingFun != null) _doubleAnimation.EasingFunction = EasingFun; Storyboard.SetTargetProperty(_doubleAnimation, new PropertyPath(PropertyPath)); return _doubleAnimation; }
private void StartAnimation(EasingFunctionBase easingFunction) { // show the chart chartControl.Draw(easingFunction); // animation NameScope.SetNameScope(translate1, new NameScope()); var storyboard = new Storyboard(); var ellipseMove = new DoubleAnimation(); ellipseMove.EasingFunction = easingFunction; ellipseMove.Duration = new Duration(TimeSpan.FromSeconds(AnimationTimeSeconds)); ellipseMove.From = 0; ellipseMove.To = 460; Storyboard.SetTargetName(ellipseMove, nameof(translate1)); Storyboard.SetTargetProperty(ellipseMove, new PropertyPath(TranslateTransform.XProperty)); ellipseMove.BeginTime = TimeSpan.FromSeconds(1.5); // start animation in 0.5 seconds ellipseMove.FillBehavior = FillBehavior.HoldEnd; // keep position after animation storyboard.Children.Add(ellipseMove); storyboard.Begin(this); }
public static Storyboard ScaleAnimation(this UIElement element, double beginTimeInSeconds, double durationInSeconds, double fromScaleX, double fromScaleY, double toScaleX, double toScaleY , EasingFunctionBase easingFunction = null, Storyboard sb = null, RepeatBehavior? repeatBehavior = null, bool autoReverse = false) { if (sb == null) sb = new Storyboard(); Storyboard.SetTarget(sb, element); int? transformGroupIndex; string scaleXProp, scaleYProp; var scaleTransform = element.FindTransform<ScaleTransform>(out transformGroupIndex); if (scaleTransform == null) throw new Exception("No scale transformation found on target element."); if (transformGroupIndex.HasValue) { scaleXProp = "(UIElement.RenderTransform).(TransformGroup.Children)[" + transformGroupIndex + "].(ScaleTransform.ScaleX)"; scaleYProp = "(UIElement.RenderTransform).(TransformGroup.Children)[" + transformGroupIndex + "].(ScaleTransform.ScaleY)"; } else { scaleXProp = "(UIElement.RenderTransform).(ScaleTransform.ScaleX)"; scaleYProp = "(UIElement.RenderTransform).(ScaleTransform.ScaleY)"; } DoubleAnimationUsingKeyFrames scaleXAnim = Util.CreateDoubleAnimationUsingKeyFrames(scaleXProp, beginTimeInSeconds, new AnimationKeyFrame(fromScaleX, 0, easingFunction), new AnimationKeyFrame(toScaleX, durationInSeconds, easingFunction)); DoubleAnimationUsingKeyFrames scaleYAnim = Util.CreateDoubleAnimationUsingKeyFrames(scaleYProp, beginTimeInSeconds, new AnimationKeyFrame(fromScaleY, 0, easingFunction), new AnimationKeyFrame(toScaleY, durationInSeconds, easingFunction)); if (repeatBehavior.HasValue) { scaleXAnim.RepeatBehavior = scaleYAnim.RepeatBehavior = repeatBehavior.Value; } sb.AutoReverse = autoReverse; sb.Children.Add(scaleXAnim); sb.Children.Add(scaleYAnim); return sb; }
/// <summary> /// Derived classes can override this method to handle changes to the Easing property. /// </summary> /// <param name="oldValue"></param> /// <param name="newValue"></param> protected virtual void OnEasingChanged(EasingFunctionBase oldValue, EasingFunctionBase newValue) { }
public EasingFunctionModel(EasingFunctionBase easingFunction) { EasingFunction = easingFunction; }
public AnimAdorner(UIElement adornedElement, UIElement ChildElement, Duration MoveDuration, EasingFunctionBase Easing) : base(adornedElement) { var ic = adornedElement as FrameworkElement; var fe = ChildElement as FrameworkElement; var point = fe.TransformToVisual(ic).Transform(new Point(0, 0)); sizeSrc = new Size(fe.ActualWidth, fe.ActualHeight); var bitmap = RenderToBitmap(ChildElement); var tg = new TransformGroup(); var st = new ScaleTransform(1, 1); tg.Children.Add(st); var tt = new TranslateTransform(point.X, point.Y); tg.Children.Add(tt); var imgSrc = new Image(); imgSrc.Visibility = System.Windows.Visibility.Visible; imgSrc.Source = bitmap; imgSrc.Stretch = Stretch.None; gridChild = new Grid(); gridChild.Visibility = System.Windows.Visibility.Visible; gridChild.Children.Add(imgSrc); gridChild.RenderTransform = tg; this.AddVisualChild(gridChild); Storyboard sb = new Storyboard(); DoubleAnimation daX = new DoubleAnimation(); daX.Duration = MoveDuration; daX.EasingFunction = Easing; Storyboard.SetTarget(daX, gridChild); Storyboard.SetTargetProperty(daX, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[1].(TranslateTransform.X)")); sb.Children.Add(daX); DoubleAnimation daY = new DoubleAnimation(); daY.Duration = MoveDuration; daY.EasingFunction = Easing; Storyboard.SetTarget(daY, gridChild); Storyboard.SetTargetProperty(daY, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[1].(TranslateTransform.Y)")); sb.Children.Add(daY); DoubleAnimation daSX = new DoubleAnimation(); daSX.Duration = MoveDuration; daSX.EasingFunction = Easing; Storyboard.SetTarget(daSX, gridChild); Storyboard.SetTargetProperty(daSX, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)")); sb.Children.Add(daSX); DoubleAnimation daSY = new DoubleAnimation(); daSY.Duration = MoveDuration; daSY.EasingFunction = Easing; Storyboard.SetTarget(daSY, gridChild); Storyboard.SetTargetProperty(daSY, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)")); sb.Children.Add(daSY); DoubleAnimation daO = new DoubleAnimation(); daO.To = 0; Storyboard.SetTarget(daO, imgSrc); Storyboard.SetTargetProperty(daO, new PropertyPath("Opacity")); sb.Children.Add(daO); sb2PointSize = sb; }
/// <summary> /// Creates the animation for translating the element /// to a new location /// </summary> /// <param name="element">Item to be translated</param> /// <param name="translation">Translation value</param> /// <param name="period">Translation duration</param> /// <param name="easing">Easing function</param> /// <returns>Storyboard</returns> private static Storyboard CreateTransition(UIElement element, Point translation, TimeSpan period, EasingFunctionBase easing) { Duration duration = new Duration(period); // Animate X var translateAnimationX = new DoubleAnimation(); translateAnimationX.To = translation.X; translateAnimationX.Duration = duration; if (easing != null) translateAnimationX.EasingFunction = easing; Storyboard.SetTarget(translateAnimationX, element); Storyboard.SetTargetProperty(translateAnimationX, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.X)")); var sb = new Storyboard(); sb.Children.Add(translateAnimationX); return sb; }
/// <summary> /// Creates the transition animation for an element. /// </summary> /// <param name="element">Child element to move.</param> /// <param name="position">New position of the child element.</param> /// <param name="duration">Duration of the animation.</param> /// <returns></returns> protected Storyboard CreateTransition(UIElement element, Point position, TimeSpan duration, EasingFunctionBase easing) { // Animate along X axis DoubleAnimation tx = new DoubleAnimation {To = position.X, Duration = duration}; if (Easing != null) tx.EasingFunction = easing; Storyboard.SetTarget(tx, element); Storyboard.SetTargetProperty(tx, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[1].(TranslateTransform.X)")); // Animate along Y axis DoubleAnimation ty = new DoubleAnimation {To = position.Y, Duration = duration}; if (Easing != null) ty.EasingFunction = easing; Storyboard.SetTarget(ty, element); Storyboard.SetTargetProperty(ty, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[1].(TranslateTransform.Y)")); // Animate X axis scale DoubleAnimation sx = new DoubleAnimation {To = 1.0D, Duration = duration}; if (Easing != null) sx.EasingFunction = easing; Storyboard.SetTarget(sx, element); Storyboard.SetTargetProperty(sx, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)")); // Animate Y axis scale DoubleAnimation sy = new DoubleAnimation {To = 1.0D, Duration = duration}; if (Easing != null) sy.EasingFunction = easing; Storyboard.SetTarget(sy, element); Storyboard.SetTargetProperty(sy, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)")); // Assemble animation Storyboard board = new Storyboard {Duration = duration}; board.Children.Add(tx); board.Children.Add(ty); board.Children.Add(sx); board.Children.Add(sy); board.Completed += (s, e) => element.SetValue(ZIndexProperty, DefaultZ); return board; }
/// <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) { }
/// <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 PanAnimation(FrameworkElement element) { this.element = element; this.element.RenderTransform = new TranslateTransform(); this.easingFunction = new QuarticEase { EasingMode = EasingMode.EaseOut }; }
public static Storyboard XYAnimation(this UIElement element, double beginTimeInSeconds, double durationInSeconds, double? toX = null, double? toY = null , EasingFunctionBase easingFunction = null, Storyboard sb = null, RepeatBehavior? repeatBehavior = null, bool autoReverse = false) { if (sb == null) sb = new Storyboard(); Storyboard.SetTarget(sb, element); int? transformGroupIndex; string xProp, yProp; var translateTransform = element.FindTransform<TranslateTransform>(out transformGroupIndex); if (translateTransform == null) throw new Exception("No translate transformation found on target element."); if (transformGroupIndex.HasValue) { xProp = "(UIElement.RenderTransform).(TransformGroup.Children)[" + transformGroupIndex + "].(TranslateTransform.X)"; yProp = "(UIElement.RenderTransform).(TransformGroup.Children)[" + transformGroupIndex + "].(TranslateTransform.Y)"; } else { xProp = "(UIElement.RenderTransform).(TransformGroup.X)"; yProp = "(UIElement.RenderTransform).(TransformGroup.Y)"; } if (toX.HasValue) { DoubleAnimation xAnim = new DoubleAnimation(); sb.Children.Add(xAnim); xAnim.BeginTime = TimeSpan.FromSeconds(beginTimeInSeconds); xAnim.Duration = TimeSpan.FromSeconds(durationInSeconds); xAnim.To = toX.Value; Storyboard.SetTargetProperty(xAnim, new PropertyPath(xProp)); Storyboard.SetTarget(xAnim, element); if (repeatBehavior.HasValue) { xAnim.RepeatBehavior = repeatBehavior.Value; } } if (toY.HasValue) { DoubleAnimation yAnim = new DoubleAnimation(); sb.Children.Add(yAnim); yAnim.BeginTime = TimeSpan.FromSeconds(beginTimeInSeconds); yAnim.Duration = TimeSpan.FromSeconds(durationInSeconds); yAnim.To = toY.Value; Storyboard.SetTargetProperty(yAnim, new PropertyPath(yProp)); Storyboard.SetTarget(yAnim, element); if (repeatBehavior.HasValue) { yAnim.RepeatBehavior = repeatBehavior.Value; } } sb.AutoReverse = autoReverse; return sb; }
public static Storyboard ScaleUniformAnimation(this UIElement element, double beginTimeInSeconds, double durationInSeconds, double fromScale, double toScale, EasingFunctionBase easingFunction = null, Storyboard sb = null, RepeatBehavior? repeatBehavior = null, bool autoReverse = false) { return element.ScaleAnimation(beginTimeInSeconds, durationInSeconds, fromScale, fromScale, toScale, toScale, easingFunction, sb, repeatBehavior, autoReverse); }