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 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); }
private void StoryBoardInit(double left) { QuinticEase SineEase = new QuinticEase { EasingMode = EasingMode.EaseIn }; ThicknessAnimationUsingKeyFrames keyFrames = new ThicknessAnimationUsingKeyFrames(); EasingThicknessKeyFrame keyFrame = new EasingThicknessKeyFrame(new Thickness(left, this.Margin.Top, this.Margin.Right, this.Margin.Bottom), KeyTime.FromTimeSpan(TimeSpan.FromSeconds(5)), SineEase); EasingThicknessKeyFrame keyFrame1 = new EasingThicknessKeyFrame(new Thickness(0, this.Margin.Top, this.Margin.Right, this.Margin.Bottom), KeyTime.FromTimeSpan(TimeSpan.FromSeconds(10)), SineEase); this.Margin = new Thickness(0,this.Margin.Top,this.Margin.Right,this.Margin.Bottom); keyFrames.RepeatBehavior = RepeatBehavior.Forever; StoryBoard.Children.Clear(); keyFrames.KeyFrames.Add(keyFrame); keyFrames.KeyFrames.Add(keyFrame1); StoryBoard.Children.Add(keyFrames); Storyboard.SetTargetProperty(keyFrames, new PropertyPath("(FrameworkElement.Margin)")); Storyboard.SetTarget(keyFrames, this); StoryBoard.FillBehavior = FillBehavior.HoldEnd; StoryBoard.Begin(); }
private void DehightlightNote(Note note) { List<Tuple<byte, byte>> lst = _guitar.GetFretsForNote(note); foreach (var objName in lst) { object o = LogicalTreeHelper.FindLogicalNode(FretsGrid, GenerateFretName(objName.Item1, objName.Item2)); if (o != null) { var shape = o as Shape; Brush brushCopy = shape.Fill.Clone(); shape.Fill = brushCopy; var fretFadeAnimation = new ColorAnimation(((SolidColorBrush) shape.Fill).Color, _inactiveFret.Color, new Duration(TimeSpan.FromSeconds(2))); var easing = new QuinticEase {EasingMode = EasingMode.EaseOut}; fretFadeAnimation.EasingFunction = easing; var fretStoryboard = new Storyboard(); fretStoryboard.Children.Add(fretFadeAnimation); string elementName = shape.Name; if (FindName(elementName) == null) { RegisterName(elementName, shape); } Storyboard.SetTargetName(fretFadeAnimation, elementName); Storyboard.SetTargetProperty(fretFadeAnimation, new PropertyPath("Fill.Color")); fretStoryboard.Begin(this); } } TChordName.Text = ""; string str = GenerateKeyName(note); var bNote = (TextBlock) LogicalTreeHelper.FindLogicalNode(KeysGrid, str); if (bNote != null) { FreeColor(((SolidColorBrush) bNote.Background).Color); SolidColorBrush targetColor = str.Length == 2 ? _genericColor : _diezColor; Brush brushCopy = bNote.Background.Clone(); bNote.Background = brushCopy; var noteFadeAnimation = new ColorAnimation(((SolidColorBrush) bNote.Background).Color, targetColor.Color, new Duration(TimeSpan.FromSeconds(3))); var easing = new QuinticEase {EasingMode = EasingMode.EaseOut}; noteFadeAnimation.EasingFunction = easing; var noteStoryboadrd = new Storyboard(); noteStoryboadrd.Children.Add(noteFadeAnimation); if (FindName(bNote.Name) == null) { RegisterName(bNote.Name, bNote); } Storyboard.SetTargetName(noteFadeAnimation, bNote.Name); Storyboard.SetTargetProperty(noteFadeAnimation, new PropertyPath("Background.Color")); noteStoryboadrd.Begin(this); } }
private void AnimateGraphic() { MapPoint userStartPoint = _userInteractionLayer.Graphics[0].Geometry as MapPoint; MapPoint userFinishPoint = _userInteractionLayer.Graphics[1].Geometry as MapPoint; MapPoint startPoint = GeometryEngine.NormalizeCentralMeridian(userStartPoint) as MapPoint; MapPoint finishPoint = GeometryEngine.NormalizeCentralMeridian(userFinishPoint) as MapPoint; var animatingGraphic = new Graphic(new MapPoint(startPoint.X, startPoint.Y)); _animatingLayer.Graphics.Add(animatingGraphic); // Framework easing objects may be used to calculate progressive values // - i.e. QuinticEase, BackEase, BounceEase, ElasticEase, etc. var easing = new QuinticEase() { EasingMode = EasingMode.EaseInOut }; var animateStartTime = DateTime.Now; var animationTimer = new DispatcherTimer(); animationTimer.Interval = TimeSpan.FromMilliseconds(33); animationTimer.Tick += (s, ex) => { double fraction = easing.Ease((DateTime.Now - animateStartTime).TotalMilliseconds / AnimationDuration); var x = (finishPoint.X - startPoint.X) * fraction + startPoint.X; var y = (finishPoint.Y - startPoint.Y) * fraction + startPoint.Y; animatingGraphic.Geometry = new MapPoint(x, y); }; animationTimer.Start(); }
private IEasingFunction ObterFuncaoDaAnimacao() { EasingFunctionBase funcaoDaAnimacao = null; switch (FuncaoDaAnimacao.SelectedValue.ToString()) { case "BackEase": funcaoDaAnimacao = new BackEase(); break; case "BounceEase": funcaoDaAnimacao = new BounceEase(); break; case "CircleEase": funcaoDaAnimacao = new CircleEase(); break; case "CubicEase": funcaoDaAnimacao = new CubicEase(); break; case "ElasticEase": funcaoDaAnimacao = new ElasticEase(); break; case "ExponentialEase": funcaoDaAnimacao = new ExponentialEase(); break; case "PowerEase": funcaoDaAnimacao = new PowerEase(); break; case "QuadraticEase": funcaoDaAnimacao = new QuadraticEase(); break; case "QuarticEase": funcaoDaAnimacao = new QuarticEase(); break; case "QuinticEase": funcaoDaAnimacao = new QuinticEase(); break; case "SineEase": funcaoDaAnimacao = new SineEase(); break; } funcaoDaAnimacao.EasingMode = ObterModoDaAnimacao(); return funcaoDaAnimacao; }
public static PlotElementAnimation CreateAnimation(AnimationTransform transform, AnimationOrigin origin, Easing easing, bool indexDelay) { var sb = new Storyboard(); var duration = new Duration(TimeSpan.FromSeconds(0.5)); var style = new Style(); style.TargetType = typeof(PlotElement); style.Setters.Add(new Setter(PlotElement.OpacityProperty, 0.0)); if (transform == AnimationTransform.Scale) style.Setters.Add(new Setter(PlotElement.RenderTransformProperty, new ScaleTransform() { ScaleX = 0, ScaleY = 0 })); else if (transform == AnimationTransform.Rotation) style.Setters.Add(new Setter(PlotElement.RenderTransformProperty, new RotateTransform() { Angle = 180 })); var point = new Point(0.5, 0.5); switch (origin) { case AnimationOrigin.Bottom: point = new Point(0.5, 2); break; case AnimationOrigin.Top: point = new Point(0.5, -2); break; case AnimationOrigin.Left: point = new Point(-2, 0.5); break; case AnimationOrigin.Right: point = new Point(2, 0.5); break; case AnimationOrigin.TopLeft: point = new Point(2, -2); break; case AnimationOrigin.TopRight: point = new Point(-2, -2); break; case AnimationOrigin.BottomLeft: point = new Point(2, 2); break; case AnimationOrigin.BottomRight: point = new Point(-2, 2); break; default: break; } style.Setters.Add(new Setter(PlotElement.RenderTransformOriginProperty, point)); var da = new DoubleAnimation() { From = 0, To = 1, Duration = duration }; Storyboard.SetTargetProperty(da, new PropertyPath("Opacity")); sb.Children.Add(da); if (transform == AnimationTransform.Scale) { var da2 = new DoubleAnimation() { From = 0, To = 1, Duration = duration }; Storyboard.SetTargetProperty(da2, new PropertyPath("(RenderTransform).ScaleX")); var da3 = new DoubleAnimation() { From = 0, To = 1, Duration = duration }; Storyboard.SetTargetProperty(da3, new PropertyPath("(RenderTransform).ScaleY")); sb.Children.Add(da2); sb.Children.Add(da3); } else if (transform == AnimationTransform.Rotation) { var da2 = new DoubleAnimation() { To = 0, Duration = duration }; Storyboard.SetTargetProperty(da2, new PropertyPath("(RenderTransform).Angle")); sb.Children.Add(da2); } if (indexDelay) { foreach (var anim in sb.Children) PlotElementAnimation.SetIndexDelay(anim, 0.5); } #if CLR40 if (easing != Easing.None) { IEasingFunction ef = null; switch (easing) { case Easing.BackEase: ef = new BackEase(); break; case Easing.BounceEase: ef = new BounceEase(); break; case Easing.CircleEase: ef = new CircleEase(); break; case Easing.CubicEase: ef = new CubicEase(); break; case Easing.ElasticEase: ef = new ElasticEase(); break; case Easing.ExponentialEase: ef = new ExponentialEase(); break; case Easing.PowerEase: ef = new PowerEase(); break; case Easing.QuadraticEase: ef = new QuadraticEase(); break; case Easing.QuarticEase: ef = new QuarticEase(); break; case Easing.QuinticEase: ef = new QuinticEase(); break; case Easing.SineEase: ef = new SineEase(); break; default: break; } foreach (DoubleAnimation anim in sb.Children) anim.EasingFunction = ef; } #endif return new PlotElementAnimation() { Storyboard = sb, SymbolStyle = style }; }