public static void AnimateImageSourceChange(this Image image, ImageSource bitmap, Action<Image> onShowImage, AnimateImageChangeParams animateImageChangeParams = null) { var animationParameters = animateImageChangeParams ?? new AnimateImageChangeParams(); var fadeInAnimation = new DoubleAnimation(animationParameters.TargetOpacity, animationParameters.FadeTime); if (image.Source != null) { var fadeOutAnimation = new DoubleAnimation(0d, animationParameters.FadeTime); fadeOutAnimation.Completed += (o, e) => { image.Source = bitmap; onShowImage(image); image.BeginAnimation(UIElement.OpacityProperty, fadeInAnimation); }; image.BeginAnimation(UIElement.OpacityProperty, fadeOutAnimation); } else { image.Opacity = 0d; image.Source = bitmap; onShowImage(image); image.BeginAnimation(UIElement.OpacityProperty, fadeInAnimation); } }
/// <summary> /// Animates the camera position and directions. /// </summary> /// <param name="camera"> /// The camera to animate. /// </param> /// <param name="newPosition"> /// The position to animate to. /// </param> /// <param name="newDirection"> /// The direction to animate to. /// </param> /// <param name="newUpDirection"> /// The up direction to animate to. /// </param> /// <param name="animationTime"> /// Animation time in milliseconds. /// </param> public static void AnimateTo( this Camera camera, Point3D newPosition, Vector3D newDirection, Vector3D newUpDirection, double animationTime) { var projectionCamera = camera as ProjectionCamera; if (projectionCamera == null) { return; } var fromPosition = projectionCamera.Position; var fromDirection = projectionCamera.LookDirection; var fromUpDirection = projectionCamera.UpDirection; projectionCamera.Position = newPosition; projectionCamera.LookDirection = newDirection; projectionCamera.UpDirection = newUpDirection; if (animationTime > 0) { var a1 = new Point3DAnimation( fromPosition, newPosition, new Duration(TimeSpan.FromMilliseconds(animationTime))) { AccelerationRatio = 0.3, DecelerationRatio = 0.5, FillBehavior = FillBehavior.Stop }; a1.Completed += (s, a) => { camera.BeginAnimation(ProjectionCamera.PositionProperty, null); }; camera.BeginAnimation(ProjectionCamera.PositionProperty, a1); var a2 = new Vector3DAnimation( fromDirection, newDirection, new Duration(TimeSpan.FromMilliseconds(animationTime))) { AccelerationRatio = 0.3, DecelerationRatio = 0.5, FillBehavior = FillBehavior.Stop }; a2.Completed += (s, a) => { camera.BeginAnimation(ProjectionCamera.LookDirectionProperty, null); }; camera.BeginAnimation(ProjectionCamera.LookDirectionProperty, a2); var a3 = new Vector3DAnimation( fromUpDirection, newUpDirection, new Duration(TimeSpan.FromMilliseconds(animationTime))) { AccelerationRatio = 0.3, DecelerationRatio = 0.5, FillBehavior = FillBehavior.Stop }; a3.Completed += (s, a) => { camera.BeginAnimation(ProjectionCamera.UpDirectionProperty, null); }; camera.BeginAnimation(ProjectionCamera.UpDirectionProperty, a3); } }
public static void animateHeight(this UIElement element, DependencyProperty prop, double height, int mode) { double newHeight; ElasticEase cc = new ElasticEase(); if (mode == 1) { newHeight = 260; } else if(mode == 2) { newHeight = 520; } else { newHeight = 0; } if(height != newHeight) { DoubleAnimation op = new DoubleAnimation(height, newHeight, program.tSpan); cc.Springiness = 5; cc.Oscillations = 1; op.EasingFunction = cc; cc.EasingMode = EasingMode.EaseInOut; element.BeginAnimation(prop, op); } }
public static void AnimateEase(this Animatable obj, DependencyProperty property, double fromValue, double toValue, TimeSpan duration) { var anim = new DoubleAnimation(fromValue, toValue, new Duration(duration)); anim.AccelerationRatio = 0.5; anim.DecelerationRatio = 0.5; obj.BeginAnimation(property, anim); }
public static void ShowwithAnimation(this Window window) { window.Visibility = Visibility.Visible; window.Topmost = false; TimeSpan slidetime = TimeSpan.FromSeconds(0.3); DoubleAnimation bottomAnimation = new DoubleAnimation(); bottomAnimation.Duration = new Duration(slidetime); double top = window.Top; bottomAnimation.From = window.Top + 25; bottomAnimation.To = window.Top; bottomAnimation.FillBehavior = FillBehavior.Stop; bottomAnimation.Completed += (s, e) => { window.Topmost = true; // Set the final position again. This covers a case where frames are dropped. // and the window ends up over the taskbar instead. window.Top = top; window.Activate(); window.Focus(); }; var easing = new QuinticEase(); easing.EasingMode = EasingMode.EaseOut; bottomAnimation.EasingFunction = easing; window.BeginAnimation(Window.TopProperty, bottomAnimation); }
public static void Animation_Opacity_View_Frame(this UIElement E, bool isview = true, Action CompleteAction = null, double minisecond=500) { Visibility visibility = E.Visibility; if (visibility != Visibility.Visible) { E.Visibility = Visibility.Visible; } DoubleAnimation da = new DoubleAnimation() { Duration = TimeSpan.FromMilliseconds(minisecond), EasingFunction = new PowerEase() { Power = 4, EasingMode = EasingMode.EaseInOut } }; if (isview) { da.From = E.Opacity; da.To = 1; } else { da.From = E.Opacity; da.To = 0; } da.Completed += (o, e) => { if (!isview) E.Visibility = Visibility.Hidden; if (CompleteAction != null) { CompleteAction(); } }; E.BeginAnimation(UIElement.OpacityProperty, da); }
/// <summary> /// Animates the opacity of the specified object. /// </summary> /// <param name="obj"> /// The object to animate. /// </param> /// <param name="targetOpacity"> /// The target opacity. /// </param> /// <param name="animationTime"> /// The animation time. /// </param> public static void AnimateOpacity(this IAnimatable obj, double targetOpacity, double animationTime) { var animation = new DoubleAnimation(targetOpacity, new Duration(TimeSpan.FromMilliseconds(animationTime))) { AccelerationRatio = 0.3, DecelerationRatio = 0.5 }; obj.BeginAnimation(UIElement.OpacityProperty, animation); }
public static void AnimateTo(this RowDefinition row, double pixelValue, TimeSpan duration) { GridLengthAnimation heightAnim = new GridLengthAnimation() { To = pixelValue, Duration = new Duration(duration) }; row.BeginAnimation(RowDefinition.HeightProperty, heightAnim); }
/// <summary>Fades the specified source opacity.</summary> /// <param name="control">The <c>control</c>.</param> /// <param name="sourceOpacity">The source opacity.</param> /// <param name="targetOpactity">The target <c>opactity</c>.</param> /// <param name="milliseconds">The <c>milliseconds</c>.</param> /// <exception cref="OverflowException"><paramref> /// <name>value</name> /// </paramref> /// is less than <see cref="F:System.TimeSpan.MinValue" /> or greater than <see cref="F:System.TimeSpan.MaxValue" />.-or-<paramref> /// <name>value</name> /// </paramref> /// is <see cref="F:System.Double.PositiveInfinity" />.-or-<paramref> /// <name>value</name> /// </paramref> /// is <see cref="F:System.Double.NegativeInfinity" />. </exception> public static void Fade(this UIElement control, double sourceOpacity, double targetOpactity, int milliseconds) { control.BeginAnimation( UIElement.OpacityProperty, new DoubleAnimation( sourceOpacity, targetOpactity, new Duration(TimeSpan.FromMilliseconds(milliseconds)))); }
public static void AnimateTo(this ColumnDefinition column, double pixelValue, TimeSpan duration) { GridLengthAnimation widthAnim = new GridLengthAnimation() { To = pixelValue, Duration = new Duration(duration) }; column.BeginAnimation(ColumnDefinition.WidthProperty, widthAnim); }
public static void animateOpacity(this UIElement element, DependencyProperty prop, double from = 0, double to = 1) { double opa = element.Opacity; if (opa == from) { DoubleAnimation op = new DoubleAnimation(from, to, program.tSpan); element.BeginAnimation(prop, op); } if (to == 0) element.Visibility = Visibility.Hidden; else element.Visibility = Visibility.Visible; }
public static void BeginDoubleAnimation(this DependencyObject target, string path, double? to, Duration duration) { var animation = new DoubleAnimation { To = to, Duration = duration, EnableDependentAnimation = true }; target.BeginAnimation(animation, path); }
/// <summary> /// Provides an animation while changing the source of an <see cref="Image"/> control. /// </summary> /// <param name="image">The target <see cref="Image"/> control.</param> /// <param name="source">The new <see cref="ImageSource"/> value.</param> /// <param name="fadeOutDuration">The duration to run the fade out animation for.</param> /// <param name="fadeInDuration">The duration to run the fade out animation for.</param> public static void AnimateSourceChange(this Image image, ImageSource source, TimeSpan fadeOutDuration, TimeSpan fadeInDuration) { var fadeInAnimation = new DoubleAnimation(1d, fadeInDuration); if (image.Source != null && fadeOutDuration > TimeSpan.Zero) { var fadeOutAnimation = new DoubleAnimation(0d, fadeOutDuration); fadeOutAnimation.Completed += (o, e) => { image.Source = source; image.BeginAnimation(UIElement.OpacityProperty, fadeInAnimation); }; image.BeginAnimation(UIElement.OpacityProperty, fadeOutAnimation); } else { image.Opacity = 0d; image.Source = source; image.BeginAnimation(UIElement.OpacityProperty, fadeInAnimation); } }
public static void ChangeSource(this Image image, ImageSource source, TimeSpan fadeOutTime, TimeSpan fadeInTime) { var fadeInAnimation = new DoubleAnimation(1d, fadeInTime); if (image.Source != null) { var fadeOutAnimation = new DoubleAnimation(0d, fadeOutTime); fadeOutAnimation.Completed += (o, e) => { image.Source = source; image.BeginAnimation(Image.OpacityProperty, fadeInAnimation); }; image.BeginAnimation(Image.OpacityProperty, fadeOutAnimation); } else { image.Opacity = 0d; image.Source = source; image.BeginAnimation(Image.OpacityProperty, fadeInAnimation); } }
public static void Animation_Color_Repeat(this SolidColorBrush E, Color from, Color to, double time = 500) { if (from == null) { from = E.GetColor(); } ColorAnimation animation = new ColorAnimation(); animation.From = from; animation.To = to; animation.Duration = TimeSpan.FromMilliseconds(time); animation.RepeatBehavior = RepeatBehavior.Forever; animation.EasingFunction = new PowerEase() { EasingMode = EasingMode.EaseInOut, Power = 3 }; E.BeginAnimation(SolidColorBrush.ColorProperty, animation); }
public static UIElement FadeFromTo(this UIElement uiElement, double fromOpacity, double toOpacity, int durationInMilliseconds, bool loopAnimation, bool showOnStart, bool collapseOnFinish) { var timeSpan = TimeSpan.FromMilliseconds(durationInMilliseconds); var doubleAnimation = new DoubleAnimation(fromOpacity, toOpacity, new Duration(timeSpan)); if (loopAnimation) doubleAnimation.RepeatBehavior = RepeatBehavior.Forever; uiElement.BeginAnimation(UIElement.OpacityProperty, doubleAnimation); if (showOnStart) { uiElement.ApplyAnimationClock(UIElement.VisibilityProperty, null); uiElement.Visibility = Visibility.Visible; } if (collapseOnFinish) { var keyAnimation = new ObjectAnimationUsingKeyFrames { Duration = new Duration(timeSpan) }; keyAnimation.KeyFrames.Add(new DiscreteObjectKeyFrame(Visibility.Collapsed, KeyTime.FromTimeSpan(timeSpan))); uiElement.BeginAnimation(UIElement.VisibilityProperty, keyAnimation); } return uiElement; }
public static void HideWithAnimation(this Window window) { TimeSpan slidetime = TimeSpan.FromSeconds(0.2); DoubleAnimation topAnimation = new DoubleAnimation(); topAnimation.Duration = new Duration(slidetime); topAnimation.From = window.Top; topAnimation.To = window.Top + 10; topAnimation.FillBehavior = FillBehavior.Stop; var easing = new QuinticEase(); easing.EasingMode = EasingMode.EaseIn; topAnimation.EasingFunction = easing; topAnimation.Completed += (s, e) => { window.Visibility = Visibility.Hidden; }; window.BeginAnimation(Window.TopProperty, topAnimation); }
public static void AnimateWindowSize(this UserControl target, double oldHeight, double newHeight) { target.Height = oldHeight; target.BeginAnimation(UserControl.HeightProperty, null); Storyboard sb = new Storyboard(); var aniHeight = new DoubleAnimationUsingKeyFrames(); aniHeight.Duration = new Duration(new TimeSpan(0, 0, 0, 2)); aniHeight.KeyFrames.Add(new EasingDoubleKeyFrame(target.Height, KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0, 1)))); aniHeight.KeyFrames.Add(new EasingDoubleKeyFrame(newHeight, KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0, 1, 200)))); Storyboard.SetTarget(aniHeight, target); Storyboard.SetTargetProperty(aniHeight, new PropertyPath(UserControl.HeightProperty)); sb.Children.Add(aniHeight); sb.Begin(); }
public static void Animation_Color(this SolidColorBrush E, Color from, Color to, double time = 500, Action CompleteAction = null) { if (from == null) { from = E.GetColor(); } ColorAnimation animation = new ColorAnimation(); animation.From = from; animation.To = to; animation.Duration = TimeSpan.FromMilliseconds(time); animation.Completed += (s,e) => { if (CompleteAction != null) { CompleteAction(); } }; animation.EasingFunction = new PowerEase() { EasingMode = EasingMode.EaseInOut, Power = 3 }; E.BeginAnimation(SolidColorBrush.ColorProperty, animation); }
/// <summary> /// Effectue un fondu en utilisant une DoubleAnimation /// </summary> /// <param name="uiElement">L'element this qui subira la transformation</param> /// <param name="opacityValue">La valeur d'opacite a atteindre</param> /// <param name="startTime">Le delai avant lq commencement de l'animation</param> /// <param name="duration">La lapse de temps durant lequel l'animation se deroule</param> public static void Fade(this UIElement uiElement, double opacityValue, double startTime, double duration) { var animation = new DoubleAnimation { To = opacityValue, BeginTime = TimeSpan.FromSeconds(startTime), Duration = TimeSpan.FromSeconds(duration), FillBehavior = FillBehavior.Stop }; animation.Completed += (s, a) => uiElement.Opacity = opacityValue; uiElement.BeginAnimation(UIElement.OpacityProperty, animation); }
/* public static void Animation_Translate_Frame(this UIElement E, double toX, double toY, double minisecond = 500, bool AutoReverse=false) { BounceEase BounceOrientation = new BounceEase(); BounceOrientation.Bounces = 1; BounceOrientation.Bounciness = 1; // BounceOrientation.EasingMode = EasingMode.EaseInOut; if (!double.IsNaN(toX)) { double fromX = E.getLeft(); DoubleAnimation da = new DoubleAnimation(fromX, toX+fromX, TimeSpan.FromMilliseconds(minisecond)) { EasingFunction = BounceOrientation }; da.AutoReverse = AutoReverse; E.BeginAnimation(Canvas.LeftProperty, da); } if (!double.IsNaN(toY)) { double fromY = E.getTop(); DoubleAnimation db = new DoubleAnimation(fromY, fromY + toY, TimeSpan.FromMilliseconds(minisecond)) { EasingFunction = BounceOrientation }; db.AutoReverse = AutoReverse; E.BeginAnimation(Canvas.TopProperty, db); } } * */ public static void Animation_Goto(this UIElement E, double toX, double toY, double minisecond = 500, bool AutoReverse = false) { BounceEase BounceOrientation = new BounceEase(); BounceOrientation.Bounces = 1; BounceOrientation.Bounciness = 1; // BounceOrientation.EasingMode = EasingMode.EaseInOut; if (!double.IsNaN(toX)) { double fromX = E.getLeft(); DoubleAnimation da = new DoubleAnimation(fromX, toX + fromX, TimeSpan.FromMilliseconds(minisecond)) { EasingFunction = BounceOrientation }; da.AutoReverse = AutoReverse; E.BeginAnimation(Canvas.LeftProperty, da); } if (!double.IsNaN(toY)) { double fromY = E.getTop(); DoubleAnimation db = new DoubleAnimation(fromY, fromY + toY, TimeSpan.FromMilliseconds(minisecond)) { EasingFunction = BounceOrientation }; db.AutoReverse = AutoReverse; E.BeginAnimation(Canvas.TopProperty, db); } }
public static void Animation_Translate_Frame(this UIElement E, double fromX, double fromY, double toX, double toY, double minisecond=500, Action CompleteAction= null) { if (!double.IsNaN(toX)) { if (double.IsNaN(fromX)) { fromX = E.getLeft(); } DoubleAnimation da = new DoubleAnimation(fromX, toX, TimeSpan.FromMilliseconds(minisecond)) { EasingFunction = new PowerEase() { EasingMode = EasingMode.EaseInOut, Power = 3 } }; da.Completed += (o, e) => { if (CompleteAction != null) { CompleteAction(); } }; E.BeginAnimation(Canvas.LeftProperty, da); } if (!double.IsNaN(toY)) { if (double.IsNaN(fromY)) { fromY = E.getTop(); } DoubleAnimation db = new DoubleAnimation(fromY, toY, TimeSpan.FromMilliseconds(minisecond)) { EasingFunction = new PowerEase() { EasingMode = EasingMode.EaseInOut, Power = 3 } }; if (double.IsNaN(toX)) { db.Completed += (o, e) => { if (CompleteAction != null) { CompleteAction(); } }; } E.BeginAnimation(Canvas.TopProperty, db); } }
/// <summary> /// Animates the orthographic width. /// </summary> /// <param name="camera"> /// An orthographic camera. /// </param> /// <param name="newWidth"> /// The width to animate to. /// </param> /// <param name="animationTime"> /// Animation time in milliseconds /// </param> public static void AnimateWidth(this OrthographicCamera camera, double newWidth, double animationTime) { double fromWidth = camera.Width; camera.Width = newWidth; if (animationTime > 0) { var a1 = new DoubleAnimation( fromWidth, newWidth, new Duration(TimeSpan.FromMilliseconds(animationTime))) { AccelerationRatio = 0.3, DecelerationRatio = 0.5, FillBehavior = FillBehavior.Stop }; camera.BeginAnimation(OrthographicCamera.WidthProperty, a1); } }
public static void Animate(this Animatable obj, DependencyProperty property, Thickness fromValue, Thickness toValue, TimeSpan duration) { var anim = new ThicknessAnimation(fromValue, toValue, new Duration(duration)); obj.BeginAnimation(property, anim); }
public static void EndBrushColorAnimation(this Brush brush) { if (!brush.IsSealed) brush.BeginAnimation(SolidColorBrush.ColorProperty, null); }
public static void AnimateEase(this UIElement obj, DependencyProperty property, Thickness fromValue, Thickness toValue, TimeSpan duration) { var anim = new ThicknessAnimation(fromValue, toValue, new Duration(duration)); anim.AccelerationRatio = 0.5; anim.DecelerationRatio = 0.5; obj.BeginAnimation(property, anim); }
public static void SetPercent(this ProgressBar progressBar, double percentage) { var animation = new DoubleAnimation(percentage, Duration); progressBar.BeginAnimation(RangeBase.ValueProperty, animation); }
/// <summary> /// Change cette image avec une transition en fondu /// </summary> /// <param name="image">L'image à modifier</param> /// <param name="source">La source de la prochaine image</param> /// <param name="beginTime">Le délai en seconde après lequel la transition commence</param> /// <param name="fadeTime">Le durée de la transition</param> public static void ChangeSource(this Image image, ImageSource source, double beginTime, double fadeTime) { var fadeInAnimation = new DoubleAnimation { To = 1, BeginTime = TimeSpan.FromSeconds(fadeTime), Duration = TimeSpan.FromSeconds(beginTime) }; if (image.Source != null) { var fadeOutAnimation = new DoubleAnimation { To = 0, BeginTime = TimeSpan.FromSeconds(0.05), Duration = TimeSpan.FromSeconds(fadeTime) }; fadeOutAnimation.Completed += (o, e) => { image.Source = source; image.BeginAnimation(Image.OpacityProperty, fadeInAnimation); }; image.BeginAnimation(Image.OpacityProperty, fadeOutAnimation); } else { image.Opacity = 0d; image.Source = source; image.BeginAnimation(Image.OpacityProperty, fadeInAnimation); } }
/// <summary> /// Starts frame animation only if frames count is bigger than 1. /// </summary> /// <param name="image"></param> private static void StartFramesAnimation(this Image image) { BitmapFrame bitmapFrame = image.Source as BitmapFrame; if(bitmapFrame != null) { int framesCount = bitmapFrame.Decoder.Frames.Count; if(framesCount > 1) { Int32Animation gifAnimation = new Int32Animation( 0, // "From" value framesCount - 1, // "To" value new Duration(TimeSpan.FromMilliseconds(MILLISCONDS_PER_FRAME * framesCount)) ); gifAnimation.RepeatBehavior = RepeatBehavior.Forever; image.BeginAnimation(CurrentFrameIndexProperty, gifAnimation, HandoffBehavior.SnapshotAndReplace); } } }
private static void StopFramesAnimation(this Image image) { image.BeginAnimation(CurrentFrameIndexProperty, null); }