/// <summary> /// Fade the adorner in and make it visible. /// </summary> public void FadeInAdorner() { if (adornerShowState == AdornerShowState.Visible || adornerShowState == AdornerShowState.FadingIn) { // Already visible or fading in. return; } this.ShowAdorner(); if (adornerShowState != AdornerShowState.FadingOut) { adorner.Opacity = 0.0; } DoubleAnimation doubleAnimation = new DoubleAnimation(1.0, new Duration(TimeSpan.FromSeconds(FadeInTime))); doubleAnimation.Completed += new EventHandler(fadeInAnimation_Completed); doubleAnimation.Freeze(); adorner.BeginAnimation(FrameworkElement.OpacityProperty, doubleAnimation); adornerShowState = AdornerShowState.FadingIn; }
/// <summary> /// Starts an animation to a particular value on the specified dependency property. /// You can pass in an event handler to call when the animation has completed. /// </summary> public static void StartAnimation(UIElement animatableElement, DependencyProperty dependencyProperty, double toValue, double animationDurationSeconds, EventHandler completedEvent) { double fromValue = (double)animatableElement.GetValue(dependencyProperty); DoubleAnimation animation = new DoubleAnimation(); animation.From = fromValue; animation.To = toValue; animation.Duration = TimeSpan.FromSeconds(animationDurationSeconds); animation.Completed += delegate(object sender, EventArgs e) { // // When the animation has completed bake final value of the animation // into the property. // animatableElement.SetValue(dependencyProperty, animatableElement.GetValue(dependencyProperty)); CancelAnimation(animatableElement, dependencyProperty); if (completedEvent != null) { completedEvent(sender, e); } }; animation.Freeze(); animatableElement.BeginAnimation(dependencyProperty, animation); }
/// <summary> /// Fade the adorner out and make it visible. /// </summary> public void FadeOutAdorner() { if (adornerShowState == AdornerShowState.FadingOut) { // // Already fading out. // return; } if (adornerShowState == AdornerShowState.Hidden) { // // Adorner has already been hidden. // return; } DoubleAnimation fadeOutAnimation = new DoubleAnimation(0.0, new Duration(TimeSpan.FromSeconds(FadeOutTime))); fadeOutAnimation.Completed += new EventHandler(fadeOutAnimation_Completed); fadeOutAnimation.Freeze(); adorner.BeginAnimation(FrameworkElement.OpacityProperty, fadeOutAnimation); adornerShowState = AdornerShowState.FadingOut; }
/// <summary> /// Starts an animation to a particular value on the specified dependency property. /// You can pass in an event handler to call when the animation has completed. /// </summary> /// <param name="pAnimatableElement">The gui element to animate.</param> /// <param name="pDependencyProperty">The dependency property to animate.</param> /// <param name="pToValue">The final value of the dependency property.</param> /// <param name="pAnimationDurationSeconds">The animation duration.</param> /// <param name="pCompletedEvent">The callback executed when the animation ended.</param> public static void StartAnimation(UIElement pAnimatableElement, DependencyProperty pDependencyProperty, double pToValue, double pAnimationDurationSeconds, EventHandler pCompletedEvent) { double lFromValue = (double)pAnimatableElement.GetValue(pDependencyProperty); DoubleAnimation lAnimation = new DoubleAnimation(); lAnimation.From = lFromValue; lAnimation.To = pToValue; lAnimation.Duration = TimeSpan.FromSeconds(pAnimationDurationSeconds); lAnimation.Completed += delegate(object pSender, EventArgs pEventArgs) { // // When the animation has completed bake final value of the animation // into the property. // pAnimatableElement.SetValue(pDependencyProperty, pAnimatableElement.GetValue(pDependencyProperty)); CancelAnimation(pAnimatableElement, pDependencyProperty); if (pCompletedEvent != null) { pCompletedEvent(pSender, pEventArgs); } }; lAnimation.Freeze(); pAnimatableElement.BeginAnimation(pDependencyProperty, lAnimation); }
/// <summary> /// Sets the translation animation for the move. /// </summary> /// <param name="moveStoryboard"></param> /// <param name="move"></param> /// <param name="duration"></param> private void SetTranslationAnimation(Storyboard moveStoryboard, Move move, int duration) { // animate the piece from the current position to the ending square // the animations and timelines will not be modified so they will be freezed // set the X translation animation DoubleAnimation xAnimation = new DoubleAnimation(); xAnimation.To = SquareSize * (Board.File(move.To) - (Board.SideSquareNo / 2) + 0.5); xAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(duration)); xAnimation.BeginTime = TimeSpan.FromMilliseconds(Settings.Default.AnimationStartDelay); Storyboard.SetTargetName(xAnimation, visualPieces[move.From].GetValue(name).ToString() + "Transform"); Storyboard.SetTargetProperty(xAnimation, new PropertyPath(TranslateTransform3D.OffsetXProperty)); xAnimation.Freeze(); // set the Z translation animation DoubleAnimation zAnimation = new DoubleAnimation(); zAnimation.To = SquareSize * (Board.Rank(move.To) - (Board.SideSquareNo / 2) + 0.5); zAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(duration)); zAnimation.BeginTime = TimeSpan.FromMilliseconds(Settings.Default.AnimationStartDelay); Storyboard.SetTargetName(zAnimation, visualPieces[move.From].GetValue(name).ToString() + "Transform"); Storyboard.SetTargetProperty(zAnimation, new PropertyPath(TranslateTransform3D.OffsetZProperty)); zAnimation.Freeze(); // add the animations to the move storyboard moveStoryboard.Children.Add(xAnimation); moveStoryboard.Children.Add(zAnimation); }
DoubleAnimation CreateOpacityAnimation(double toValue) { var da = new DoubleAnimation(toValue, new Duration(TimeSpan.FromMilliseconds(555))); da.AccelerationRatio = 0.5; da.DecelerationRatio = 0.5; da.FillBehavior = FillBehavior.HoldEnd; da.Freeze(); return(da); }
/// <summary>Helper to create the zoom double animation for scaling.</summary> /// <param name="toValue">Value to animate to.</param> /// <returns>Double animation.</returns> private DoubleAnimation CreateZoomAnimation(double toValue) { var da = new DoubleAnimation(toValue, new Duration(TimeSpan.FromMilliseconds(500))); da.AccelerationRatio = 0.1; da.DecelerationRatio = 0.9; da.FillBehavior = FillBehavior.HoldEnd; da.Freeze(); return(da); }
/// <summary> /// Performs a simple animation of a double property from its current value to the "to" value over the duration. This is the most /// simple case of animation. For more complex animations, you'll need to do it the old-fashioned way. /// </summary> public static void animate <T>(this T target, DependencyProperty <double> dp, double to, double duration, IEasingFunction ease = null) where T : DependencyObject, IAnimatable { DoubleAnimation anim = new DoubleAnimation(dp.GetValue(target), to, new Duration(TimeSpan.FromSeconds(duration))); anim.EasingFunction = ease; anim.Completed += (_, args) => { target.BeginAnimation(dp, null); dp.SetValue(target, to); }; anim.Freeze(); target.BeginAnimation(dp, anim, HandoffBehavior.SnapshotAndReplace); }
static MySimpleEdgeStyle() { pathStroke = new LinearGradientBrush { GradientStops = { new GradientStop { Color = Color.FromArgb(150, 150, 255, 255), Offset = 1 }, new GradientStop { Color = Color.FromArgb(200, 0, 130, 180), Offset = 0.5 }, new GradientStop { Color = Color.FromArgb(150, 200, 255, 255), Offset = 0 } }, StartPoint = new Point(0, 0), EndPoint = new Point(1, 1), SpreadMethod = GradientSpreadMethod.Repeat, }; pathStroke.Freeze(); animatedPathStroke = new LinearGradientBrush { GradientStops = { new GradientStop { Color = Color.FromArgb(255, 255, 215, 0), Offset = 0 }, new GradientStop { Color = Color.FromArgb(255, 255, 245, 30), Offset = 0.5 }, new GradientStop { Color = Color.FromArgb(255, 255, 215, 0), Offset = 1 } }, StartPoint = new Point(0, 0), EndPoint = new Point(30, 30), SpreadMethod = GradientSpreadMethod.Repeat, Transform = new TranslateTransform(), MappingMode = BrushMappingMode.Absolute, }; // Animate Fill DoubleAnimation animation = new DoubleAnimation { From = 0, To = 60, Duration = new Duration(TimeSpan.FromMilliseconds(800)), AutoReverse = false, RepeatBehavior = RepeatBehavior.Forever }; animation.Freeze(); animatedPathStroke.Transform.BeginAnimation(TranslateTransform.XProperty, animation); }
public void InvokeCollapse() { if (_widthCollapseAnimation.From != _expandWidth) { _widthCollapseAnimation.From = _expandWidth; _widthCollapseAnimation.To = _initialWidth; _widthCollapseAnimation.Freeze(); } BeginAnimation(WidthProperty, _widthCollapseAnimation); }
/// <summary> /// Creates a new animation to hide the provided node. /// </summary> /// <param name="node">The node to hide.</param> /// <param name="owner">The PhotoExplorerControl containing the node.</param> /// <returns>A new DoubleAnimation that hides the provided node.</returns> private static DoubleAnimation GetNewHideAnimation(NodePresenter node, PhotoExplorerControl owner) { DoubleAnimation hideAnimation = new DoubleAnimation(0, NodeHideAnimationDuration); hideAnimation.FillBehavior = FillBehavior.Stop; HideAnimationManager hideAnimationManager = new HideAnimationManager(owner, node); hideAnimation.Completed += new EventHandler(hideAnimationManager.CompletedHandler); hideAnimation.Freeze(); return(hideAnimation); }
/// <summary>Helper to create the panning animation for x,y coordinates.</summary> /// <param name="toValue">New value of the coordinate.</param> /// <returns>Double animation</returns> private static DoubleAnimation CreatePanAnimation(double toValue) { var da = new DoubleAnimation(toValue, new Duration(TimeSpan.FromMilliseconds(300))) { AccelerationRatio = 0.1, DecelerationRatio = 0.9, FillBehavior = FillBehavior.HoldEnd }; da.Freeze(); return(da); }
private static DoubleAnimation GetShrinkAnimation() { DoubleAnimation animation = new DoubleAnimation(); animation.To = .8; animation.DecelerationRatio = .5; animation.Duration = s_defaultDuration; animation.Freeze(); return(animation); }
private static DoubleAnimation GetNewHideAnimation(GraphContentPresenter element, Graph owner, int key) { DoubleAnimation da = new DoubleAnimation(0, HideDuration); da.FillBehavior = FillBehavior.Stop; //da.SetValue(Timeline.DesiredFrameRateProperty, HideDesiredFrameRate); HideAnimationManager ham = new HideAnimationManager(owner, key); da.Completed += new EventHandler(ham.CompletedHandler); da.Freeze(); return(da); }
public static DoubleAnimation CreateAnimation(double from, double to, TimeSpan duration) { var animation = new DoubleAnimation { From = from, To = to, EasingFunction = easingFunction, Duration = new System.Windows.Duration(duration) }; animation.Freeze(); return(animation); }
private void messageFadeOut(double fTimeout) { // Now fade it in with an animation. DoubleAnimation pAnimation = createDoubleAnimation(0.0, fTimeout, false); pAnimation.Completed += delegate(object sender, EventArgs pEvent) { // We are now faded out so make us invisible again. brdOverlay.Visibility = Visibility.Hidden; }; pAnimation.Freeze(); brdOverlay.BeginAnimation(Canvas.OpacityProperty, pAnimation, HandoffBehavior.Compose); }
/// <summary> /// Creates the animation that moves content in or out of view. /// </summary> /// <param name="from">The starting value of the animation.</param> /// <param name="to">The end value of the animation.</param> /// <param name="whenDone">(optional) A callback that will be called when the animation has completed.</param> private static AnimationTimeline CreateAnimation(double from, double to, TimeSpan timeDuration, EventHandler whenDone = null) { var duration = new Duration(timeDuration); var anim = new DoubleAnimation(from, to, duration);// { EasingFunction = ease }; if (whenDone != null) { anim.Completed += whenDone; } anim.Freeze(); return(anim); }
/// <summary> /// Activates the provided composite sensor value on the dependency property. /// </summary> private void ActivateSensorValue(double compositeSensorValueInLux) { // update the most recently updated values to be correct _lastUpdateTime = DateTime.UtcNow; _lastValue = compositeSensorValueInLux; // animate the composite lux dependency property value for external binding DoubleAnimation animation = new DoubleAnimation(compositeSensorValueInLux, AnimationTime); animation.Freeze(); AnimateDependencyPropertyValue(LuxValueProperty, animation); }
private AnimationTimeline CreateSeparatorAnimation(double from, double to, EventHandler whenDone = null) { var duration = new Duration(TimeSpan.FromSeconds(2.0)); var anim = new DoubleAnimation(from, to, duration); if (whenDone != null) { anim.Completed += whenDone; } anim.Freeze(); return(anim); }
/// <summary> /// Creates the animation that moves content in or out of view. /// </summary> /// <param name="from">The starting value of the animation.</param> /// <param name="to">The end value of the animation.</param> /// <param name="time">The animation duration</param> /// <param name="whenDoubleAnimationDone">The when double animation done.</param> /// <returns>The animation object</returns> /// TODO: refactor this to a private method that's being used by a specific public animation method (fade,slide etc) public static AnimationTimeline CreateDoubleAnimation(double from, double to, double time, EventHandler whenDoubleAnimationDone = null) { var duration = new Duration(TimeSpan.FromSeconds(time)); var animation = new DoubleAnimation(from, to, duration); if (whenDoubleAnimationDone != null) { animation.Completed += whenDoubleAnimationDone; } animation.Freeze(); return(animation); }
/// <summary>Helper to create the zoom double animation for scaling.</summary> /// <param name="toValue">Value to animate to.</param> /// <returns>Double animation.</returns> private static DoubleAnimation CreateZoomAnimation(double toValue) { var doubleAnimation = new DoubleAnimation(toValue, new Duration(TimeSpan.FromMilliseconds(/*checkBox1.IsChecked.Value*/ true ? 300 : 0))) { AccelerationRatio = 0.1, DecelerationRatio = 0.9, FillBehavior = FillBehavior.HoldEnd }; doubleAnimation.Freeze(); return(doubleAnimation); }
public static void StartAnimation(Transform animatableElement, DependencyProperty dependencyProperty, double toValue, double durationMilliseconds, double accelerationRatio, double decelerationRatio) { DoubleAnimation animation = new DoubleAnimation(); animation.To = toValue; animation.AccelerationRatio = accelerationRatio; animation.DecelerationRatio = decelerationRatio; animation.FillBehavior = FillBehavior.HoldEnd; animation.Duration = TimeSpan.FromMilliseconds(durationMilliseconds); animation.Freeze(); animatableElement.BeginAnimation(dependencyProperty, animation, HandoffBehavior.Compose); }
private static DoubleAnimation GetRandomRotateAnimation() { double angle = (.5 - Util.Rnd.NextDouble()) * 20; DoubleAnimation animation = new DoubleAnimation(); animation.To = angle; animation.DecelerationRatio = .5; animation.Duration = s_defaultDuration; animation.Freeze(); return(animation); }
private AnimationTimeline CreateAnimation(double from, double to, Duration duration, EventHandler whenDone = null) { var anim = new DoubleAnimation(from, to, duration) { EasingFunction = EasingFunction }; if (whenDone != null) { anim.Completed += whenDone; } anim.Freeze(); return(anim); }
private void Ad_MouseLeave(object sender, MouseEventArgs e) { if (AdornerLayer.GetAdornerLayer(AssociatedObject) is AdornerLayer adornerLayer) { foreach (var adorner in AdornerLayer.GetAdornerLayer(AssociatedObject)?.GetAdorners(AssociatedObject).OfType <EllipseAdorner>().ToArray()) { DoubleAnimation doubleAnimation = new DoubleAnimation(0.0, new Duration(TimeSpan.FromSeconds(6))); doubleAnimation.Completed += new EventHandler(fadeOutAnimation_Completed); doubleAnimation.Freeze(); adorner.BeginAnimation(FrameworkElement.OpacityProperty, doubleAnimation); } } }
private void messageFadeIn(double fTimeout, bool bFadeOut) { // Now fade it in with an animation. DoubleAnimation pAnimation = createDoubleAnimation(1.0, fTimeout, false); pAnimation.Completed += delegate(object sender, EventArgs pEvent) { if (bFadeOut) { this.messageFadeOut(fTimeout); } }; pAnimation.Freeze(); brdOverlay.BeginAnimation(Canvas.OpacityProperty, pAnimation, HandoffBehavior.Compose); }
private AnimationTimeline CreateAnimation(double from, double to, EventHandler whenDone = null) { IEasingFunction ease = new BackEase { Amplitude = 0.5, EasingMode = EasingMode.EaseOut }; var duration = new Duration(TimeSpan.FromSeconds(0.5)); var anim = new DoubleAnimation(from, to, duration); //{ EasingFunction = ease }; if (whenDone != null) { anim.Completed += whenDone; } anim.Freeze(); return(anim); }
void CrossFadeGameState(UIElement first, UIElement second) { const double durationInSeconds = 1; DoubleAnimation firstAnimation = new DoubleAnimation(); firstAnimation.From = 1; firstAnimation.To = 0; firstAnimation.Duration = TimeSpan.FromSeconds(durationInSeconds); firstAnimation.EasingFunction = new QuadraticEase() { EasingMode = EasingMode.EaseIn }; first.IsHitTestVisible = false; second.IsHitTestVisible = false; View.GameStatePanel.Children.Remove(first); View.GameStatePanel.Children.Add(second); View.GameStatePanel.Children.Add(first); firstAnimation.Completed += (s, ea) => { View.GameStatePanel.Children.Remove(first); }; firstAnimation.Freeze(); DoubleAnimation secondAnimation = new DoubleAnimation(); secondAnimation.From = 0; secondAnimation.To = 1; secondAnimation.Duration = TimeSpan.FromSeconds(durationInSeconds); secondAnimation.EasingFunction = new QuadraticEase() { EasingMode = EasingMode.EaseOut }; secondAnimation.Completed += (s, ea) => { second.IsHitTestVisible = true; }; secondAnimation.Freeze(); first.BeginAnimation(UIElement.OpacityProperty, firstAnimation); second.BeginAnimation(UIElement.OpacityProperty, secondAnimation); }
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); }
Storyboard CreateStoryboard(Window w, double from, double to, TimeSpan duration) { Storyboard storyboard = new Storyboard(); DoubleAnimation animation = new DoubleAnimation() { From = from, To = to, Duration = duration }; Storyboard.SetTarget(animation, w); Storyboard.SetTargetProperty(animation, new PropertyPath(FrameworkElement.OpacityProperty)); animation.Freeze(); storyboard.Children.Add(animation); return(storyboard); }