private void button4_Click(object sender, System.Windows.RoutedEventArgs e) { //定义多关键帧动画 DoubleAnimationUsingKeyFrames daukf = new DoubleAnimationUsingKeyFrames(); sb4 = new Storyboard(); this.sb4.Completed += new System.EventHandler(Storyboard_Completed); this.button1.IsEnabled = false; this.button2.IsEnabled = false; this.button3.IsEnabled = false; this.button4.IsEnabled = false; sb4.Children.Add(daukf); //动画影响属性:元素的三维旋转(以Y轴为旋转轴) Storyboard.SetTargetProperty(daukf, new PropertyPath("(UIElement.Projection).(PlaneProjection.RotationY)")); Storyboard.SetTarget(daukf, image); //定义第1个可插入的关键帧(可以和Silverlight目前提供的11种缓动函数关联) //(缓动函数设置了关键帧之间的动画过渡状态) EasingDoubleKeyFrame kf1 = new EasingDoubleKeyFrame(); kf1.Value = 80; //设置此关键帧的目标值(旋转度数) kf1.KeyTime = new TimeSpan(0, 0, 0, 3); //设置达到目标值的时间(日,小时,分,秒) BackEase kf1be = new BackEase(); //定义具有收回效果的缓动函数对象 //EasingMode有3种选择:EaseIn、EaseOut和EaseInOut kf1be.EasingMode = EasingMode.EaseOut; //EaseOut方式 kf1.EasingFunction = kf1be; //第1帧使用缓动函数BackEase的EaseOut方式过渡 //定义第2个可插入的关键帧 EasingDoubleKeyFrame kf2 = new EasingDoubleKeyFrame(); kf2.Value = 0; kf2.KeyTime = new TimeSpan(0, 0, 0, 6); //第2帧达到第6秒 BounceEase kf2be = new BounceEase(); //定义具有反弹效果的缓动函数对象 kf2be.EasingMode = EasingMode.EaseIn; //EaseIn方式 kf2be.Bounces = 3; //反弹3次 kf2.EasingFunction = kf2be; //第2帧使用缓动函数BounceEase的EaseIn方式过渡 //定义第3个可插入的关键帧 EasingDoubleKeyFrame kf3 = new EasingDoubleKeyFrame(); kf3.Value = -80; kf3.KeyTime = new TimeSpan(0, 0, 0, 9); //第3帧达到第9秒 ElasticEase kf3ee = new ElasticEase(); //定义具有衰减振荡效果的缓动函数对象 kf3ee.EasingMode = EasingMode.EaseInOut; //EaseInOut方式 kf3ee.Oscillations = 4; //振荡次数 kf3ee.Ease(4); //衰减振荡持续时间 kf3.EasingFunction = kf3ee; //第3帧使用缓动函数ElasticEase的EaseInOut方式过渡 //定义第4个可插入的关键帧 EasingDoubleKeyFrame kf4 = new EasingDoubleKeyFrame(); kf4.Value = 0; kf4.KeyTime = new TimeSpan(0, 0, 0, 12); //第4帧达到第12秒 daukf.KeyFrames.Add(kf1); //添加关键帧 daukf.KeyFrames.Add(kf2); daukf.KeyFrames.Add(kf3); daukf.KeyFrames.Add(kf4); daukf.AutoReverse = true; //允许翻转 daukf.RepeatBehavior = new RepeatBehavior(1); //反复1次 sb4.Begin(); }
static void OnTargetValuePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { // get animated gauge var ag = (AnimatedGauge)d; // create animation var da = new DoubleAnimation(); da.EnableDependentAnimation = true; da.To = (double)e.NewValue; da.Duration = new Duration(TimeSpan.FromMilliseconds(ag.Duration)); Storyboard.SetTargetProperty(da, "Value"); Storyboard.SetTarget(da, d); // apply easing function var ef = ag.EasingFunction; if (ef == null) { var ee = new ElasticEase(); ee.Oscillations = 1; ee.Springiness = 3; ef = ee; } da.EasingFunction = ef; // play animation var sb = new Storyboard(); sb.Children.Add(da); sb.Begin(); }
/********************************* Biu Biu Biu ***********************************/ #endregion #region Methods /// <summary> /// 播放指示条动画 /// </summary> /// <param name="Angle"></param> void BeginIndicatorValueChangedAnimation(double Angle) { if (Angle < 5) // 如果EndAngle小于5度,则直接显示角度值,QuinticEase会造成过冲,EndAngle会变成负值,造成闪动 { /* 如果上一个动画还在执行中,则先停止动画 * 否则执行中的动画可能再次更改EndAngle */ if (animationclock != null && animationclock.CurrentState != ClockState.Stopped) { animationclock.Controller.Stop(); } IndicatorBar.EndAngle = Angle; } else { animation = new DoubleAnimation(); animation.Duration = new Duration(TimeSpan.FromMilliseconds(500)); animation.To = Angle; // QuinticEase ease = new QuinticEase(); ElasticEase ease = new ElasticEase() { Oscillations = 2, Springiness = 5 }; ease.EasingMode = EasingMode.EaseOut; animation.EasingFunction = ease; animationclock = animation.CreateClock(); animationclock.Completed += animationclock_Completed; IndicatorBar.ApplyAnimationClock(Arc.EndAngleProperty, animationclock, HandoffBehavior.SnapshotAndReplace); animationclock.Controller.Begin(); } }
} // menu_action // animerar ut brickorna på planen vid start private void Layout(Ellipse el, double newX, double newY) { double top = Canvas.GetTop(el); double left = Canvas.GetLeft(el); Storyboard layout = new Storyboard(); DoubleAnimation anim1 = new DoubleAnimation(left, newX, TimeSpan.FromSeconds(1)); DoubleAnimation anim2 = new DoubleAnimation(top, newY, TimeSpan.FromSeconds(1)); ElasticEase ease = new ElasticEase(); ease.EasingMode = EasingMode.EaseOut; ease.Oscillations = 3; ease.Springiness = 15; anim2.Duration = TimeSpan.FromSeconds(0); anim1.Duration = TimeSpan.FromSeconds(2); anim1.EasingFunction = ease; Storyboard.SetTarget(anim1, el); Storyboard.SetTargetProperty(anim1, new PropertyPath(Canvas.LeftProperty)); layout.Children.Add(anim1); Storyboard.SetTarget(anim2, el); Storyboard.SetTargetProperty(anim2, new PropertyPath(Canvas.TopProperty)); layout.Children.Add(anim2); layout.Begin(); }
public TileControl() { RenderTransform = new ScaleTransform(); RenderTransformOrigin = new Point(0.5, 0.5); Storyboard.SetTargetProperty(scaleAnimationX, new PropertyPath("RenderTransform.ScaleX")); Storyboard.SetTargetProperty(scaleAnimationY, new PropertyPath("RenderTransform.ScaleY")); Storyboard.SetTarget(scaleAnimationX, this); Storyboard.SetTarget(scaleAnimationY, this); // add cool elastic ease effect var ef1 = new ElasticEase(); ef1.Oscillations = 1; ef1.Springiness = SPRINGINESS; ef1.EasingMode = EasingMode.EaseOut; scaleAnimationX.EasingFunction = ef1; scaleAnimationX.Duration = new Duration(TimeSpan.FromMilliseconds(500)); // add cool elastic ease effect var ef2 = new ElasticEase(); ef2.Oscillations = 1; ef2.Springiness = SPRINGINESS; ef2.EasingMode = EasingMode.EaseOut; scaleAnimationY.EasingFunction = ef2; scaleAnimationY.Duration = new Duration(TimeSpan.FromMilliseconds(500)); storyboard.Children.Add(scaleAnimationX); storyboard.Children.Add(scaleAnimationY); }
/// <summary> /// 缓动缩放动画 (提升效率)Timeline.DesiredFrameRateProperty.OverrideMetadata(typeof(Timeline), new FrameworkPropertyMetadata { DefaultValue = 20 }); /// </summary> /// <param name="element">缩放控件</param> /// <param name="aTime">缩放时间</param> /// <param name="dFrom">缩放起始值(推荐1)</param> /// <param name="dTo">缩放结束值(推荐1.5)</param> /// <param name="aOscillations">滑过动画目标的次数(推荐5)</param> /// <param name="aSpringiness">弹簧刚度(推荐10)</param> /// <returns>返回动画对象</returns> public static AnimationClock ScaleEasingAnimation(FrameworkElement element, TimeSpan aTime, double dFrom, double dTo, int aOscillations, int aSpringiness) { ScaleTransform scale = new ScaleTransform(); element.RenderTransform = scale; element.RenderTransformOrigin = new Point(0.5, 0.5);//定义圆心位置 EasingFunctionBase easing = new ElasticEase() { EasingMode = EasingMode.EaseOut, //公式 Oscillations = aOscillations, //滑过动画目标的次数 Springiness = aSpringiness //弹簧刚度 }; DoubleAnimation scaleAnimation = new DoubleAnimation() { From = dFrom, //起始值 To = dTo, //结束值 EasingFunction = easing, //缓动函数 Duration = aTime //动画播放时间 }; AnimationClock clock = scaleAnimation.CreateClock(); scale.ApplyAnimationClock(ScaleTransform.ScaleXProperty, clock); scale.ApplyAnimationClock(ScaleTransform.ScaleYProperty, clock); return(clock); }
public IEasingFunction CreateEasing() { var ease = new ElasticEase(); ease.Oscillations = 0; ease.EasingMode = EasingMode.EaseInOut; return(ease); }
private void IsExpandedChanged() { if (Children.Count != 2) { return; } Debug.Assert(SplitRatio >= 0 && SplitRatio <= 1.0); EnsureStoryboardsLoaded(); _translateStoryboard.Stop(); if (IsExpanded) { _translateAnimations[0].From = 0; _translateAnimations[0].To = SplitRatio * ActualHeight; _translateAnimations[1].From = 0; _translateAnimations[1].To = SplitRatio * ActualHeight; EasingFunctionBase ease = new ElasticEase() { EasingMode = EasingMode.EaseOut, Oscillations = 3, Springiness = 7 }; TimeSpan duration = TimeSpan.FromMilliseconds(750); _translateAnimations[0].Duration = duration; _translateAnimations[0].EasingFunction = ease; _translateAnimations[1].Duration = duration; _translateAnimations[1].EasingFunction = ease; } else { _fullyExpanded = false; InvalidateArrange(); UpdateLayout(); _translateAnimations[0].From = SplitRatio * ActualHeight; _translateAnimations[0].To = 0; _translateAnimations[1].From = SplitRatio * ActualHeight; _translateAnimations[1].To = 0; EasingFunctionBase ease = new ExponentialEase() { EasingMode = EasingMode.EaseOut }; TimeSpan duration = TimeSpan.FromMilliseconds(150); _translateAnimations[0].Duration = duration; _translateAnimations[0].EasingFunction = ease; _translateAnimations[1].Duration = duration; _translateAnimations[1].EasingFunction = ease; } _translateStoryboard.Begin(); }
internal static EasingFunctionBase GetEase(this AnimationSettings settings) { EasingFunctionBase ease; switch (settings.Easing) { case EasingType.Back: ease = new BackEase(); break; case EasingType.Bounce: ease = new BounceEase(); break; case EasingType.Circle: ease = new CircleEase(); break; case EasingType.Cubic: ease = new CubicEase(); break; case EasingType.Elastic: ease = new ElasticEase(); break; case EasingType.Linear: ease = null; break; case EasingType.Quadratic: ease = new QuadraticEase(); break; case EasingType.Quartic: ease = new QuarticEase(); break; case EasingType.Quintic: ease = new QuinticEase(); break; case EasingType.Sine: ease = new SineEase(); break; default: ease = new CubicEase(); break; } if (ease != null) { ease.EasingMode = settings.EasingMode; } return(ease); }
public static EasingFunctionBase GetEasingFunction() { EasingFunctionBase result = null; switch (random.Next(5)) { case 0: result = new BackEase() { EasingMode = EasingMode.EaseInOut, Amplitude = 0.8 }; break; case 1: result = new BounceEase() { EasingMode = EasingMode.EaseOut, Bounces = 3, Bounciness = 8 }; break; case 2: result = new CircleEase() { EasingMode = EasingMode.EaseInOut }; break; case 3: result = new CubicEase() { EasingMode = EasingMode.EaseIn }; break; case 4: result = new ElasticEase() { EasingMode = EasingMode.EaseOut, Oscillations = 3, Springiness = 4 }; break; case 5: result = new SineEase() { EasingMode = EasingMode.EaseInOut }; break; default: result = new BackEase() { EasingMode = EasingMode.EaseInOut, Amplitude = 0.8 }; break; } return(result); }
private void ImageCanvas_PreviewKeyUp(object sender, System.Windows.Input.KeyEventArgs e) { if (e.Key == System.Windows.Input.Key.Escape) { if (storyboard_circles != null) { storyboard_circles.Stop(); } if (storyboard_scroll != null) { ScrollFinished(); } CloseWindow(); } else if (e.Key == System.Windows.Input.Key.Space) { METState.Current.SCRL_Flag = " -> Space Pressed"; if (METState.Current.SCRL_State == METState.SCRL_States.stopped) { //storyboard_scroll.Stop(); //storyboard_scroll.Children.Clear(); moveAgain(); } else if (METState.Current.SCRL_State == METState.SCRL_States.Rolling && METState.Current.SCRL_stopMode == METState.SCRL_StopMode.Manual) { //storyboard_scroll.Stop(); //storyboard_scroll.Children.Clear(); Dispatcher.BeginInvoke((Action)(() => DoSomething())); } } else if ((e.Key == System.Windows.Input.Key.Right || e.Key == System.Windows.Input.Key.Left) && METState.Current.SCRL_State == METState.SCRL_States.stopped) { //SCRL_scroll.Stop(); //SCRL_scroll.Children.Clear(); double dis = METState.Current.SCRL_image_width + border_width; dis = e.Key == System.Windows.Input.Key.Right ? _scroll.X - dis : _scroll.X + dis; ElasticEase ease = new ElasticEase(); ease.EasingMode = EasingMode.EaseOut; ease.Oscillations = 1; ease.Springiness = 8; DoubleAnimation animation_scroll = new DoubleAnimation { Duration = TimeSpan.FromSeconds(1), From = _scroll.X, To = dis, EasingFunction = ease }; Scroll(animation_scroll, false); } }
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); }
/// <summary> /// Obtiene una función de tipo muelle para la animación /// </summary> private ElasticEase GetElasticEase(ElasticEaseModel elasticEase) { ElasticEase ease = new ElasticEase(); // Asigna las propiedades ease.EasingMode = ConvertEaseMode(elasticEase.EaseMode); ease.Oscillations = elasticEase.Oscillations; ease.Springiness = elasticEase.Springiness; // Devuelve la función return(ease); }
static public void onButtonLostFocusAnimtion(Button btn) { ScaleTransform trans = new ScaleTransform(); btn.RenderTransform = trans; btn.RenderTransformOrigin = new Point(0.5, 0.5); DoubleAnimation scaleAnimation = new DoubleAnimation(1.5, 1, TimeSpan.FromMilliseconds(550), FillBehavior.HoldEnd); ElasticEase pe = new ElasticEase(); pe.EasingMode = EasingMode.EaseOut; scaleAnimation.EasingFunction = pe; trans.BeginAnimation(ScaleTransform.ScaleXProperty, scaleAnimation); trans.BeginAnimation(ScaleTransform.ScaleYProperty, scaleAnimation); }
/// <summary> /// 弹簧式放大 /// </summary> /// <param name="element"></param> public static void ScaleEasingInAnimation(this FrameworkElement element, bool isActivated = true) { ScaleTransform scale = new ScaleTransform(); if (element.RenderTransform is TransformGroup) { TransformGroup group = element.RenderTransform as TransformGroup; var item = group.Children.SingleOrDefault(entity => entity is ScaleTransform); if (item != null) { group.Children.Remove(item); } RotateTransform itemRotate = group.Children.SingleOrDefault(entity => entity is RotateTransform) as RotateTransform; scale.CenterX = itemRotate.CenterX; scale.CenterY = itemRotate.CenterY; group.Children.Add(scale); } else { element.RenderTransform = scale; element.RenderTransformOrigin = new Point(0.5, 0.5); } if (!isActivated) { scale.ScaleX = 1.2; scale.ScaleY = 1.2; return; } EasingFunctionBase easing = new ElasticEase() { EasingMode = EasingMode.EaseOut, Oscillations = 10, Springiness = 15 }; DoubleAnimation scaleAnimation = new DoubleAnimation() { //From = 1, To = 1.2, EasingFunction = easing, Duration = new TimeSpan(0, 0, 0, 1, 500), FillBehavior = FillBehavior.HoldEnd }; AnimationClock clock = scaleAnimation.CreateClock(); scale.ApplyAnimationClock(ScaleTransform.ScaleXProperty, clock, HandoffBehavior.Compose); scale.ApplyAnimationClock(ScaleTransform.ScaleYProperty, clock, HandoffBehavior.Compose); }
static public void GameOverMessegeAnimtion(Label label) { ScaleTransform trans = new ScaleTransform(); label.RenderTransform = trans; label.RenderTransformOrigin = new Point(0.5, 0.5); DoubleAnimation scaleAnimation = new DoubleAnimation(1, 1.4, TimeSpan.FromMilliseconds(900), FillBehavior.Stop); scaleAnimation.AutoReverse = true; scaleAnimation.RepeatBehavior = RepeatBehavior.Forever; ElasticEase pe = new ElasticEase(); pe.EasingMode = EasingMode.EaseInOut; scaleAnimation.EasingFunction = pe; trans.BeginAnimation(ScaleTransform.ScaleXProperty, scaleAnimation); trans.BeginAnimation(ScaleTransform.ScaleYProperty, scaleAnimation); }
private void AnimateNavigationBar(bool isFromNavigationButton) { double?tempTo = -1; // The navigation menu button cand expand or retract the navigation menu after every click // All other buttons in the navigation menu work a bit differently: // If a button is clicked and the navigation menu is retracted, it stays retracted // If a button is clicked and the navigation menu is expanded, it will retract // bool isFromNavigationButton helps in determining from which type of button the click came from if (isFromNavigationButton == false) { tempTo = 40; acrylicPanelNavbar.TintOpacity = .2; } else if (gridNavBar.ActualWidth > 40) { acrylicPanelNavbar.TintOpacity = .2; tempTo = 40; } else { acrylicPanelNavbar.TintOpacity = .8; tempTo = 245; } ElasticEase ea = new ElasticEase { EasingMode = EasingMode.EaseOut, Oscillations = 2, Springiness = 12 }; DoubleAnimation doubleAnim = new DoubleAnimation { From = gridNavBar.ActualWidth, To = tempTo, Duration = TimeSpan.FromMilliseconds(700), EasingFunction = ea }; gridNavBar.BeginAnimation(Grid.WidthProperty, doubleAnim); acrylicPanelNavbar.BeginAnimation(Grid.WidthProperty, doubleAnim); stackPanelMainNavigationBar.BeginAnimation(StackPanel.WidthProperty, doubleAnim); canvasNavBar.BeginAnimation(Canvas.WidthProperty, doubleAnim); buttonApplicationSettings.BeginAnimation(Button.WidthProperty, doubleAnim); }
/// <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) { //check the animation clock event VerifyAnimationCompletedStatus(animationClock); //check if the animation was completed if (_isCompleted) { return((GridLength)defaultDestinationValue); } //if not then create the value to animate var fromVal = From.Value; var toVal = To.Value; //check if the value is already collapsed if (Math.Abs(((GridLength)defaultOriginValue).Value - toVal) < 0.1) { fromVal = toVal; toVal = ReverseValue; } else //check to see if this is the last tick of the animation clock. { Debug.Assert(animationClock.CurrentProgress != null, "animationClock.CurrentProgress != null"); if (Math.Abs(animationClock.CurrentProgress.Value - 1.0) < 0.1) { return(To); } } EasingFunctionBase easing = new ElasticEase { Oscillations = 2, EasingMode = EasingMode.EaseOut, Springiness = 10 }; Debug.Assert(animationClock.CurrentProgress != null, "animationClock.CurrentProgress != null"); if (fromVal > toVal) { return(new GridLength((1 - easing.Ease(animationClock.CurrentProgress.Value)) * (fromVal - toVal) + toVal, From.IsStar ? GridUnitType.Star : GridUnitType.Pixel)); } return(new GridLength(easing.Ease(animationClock.CurrentProgress.Value) * (toVal - fromVal) + fromVal, From.IsStar ? GridUnitType.Star : GridUnitType.Pixel)); }
private void VanguardInfoPopup_Loaded(object sender, RoutedEventArgs e) { var ease = new ElasticEase() { Oscillations = 1 }; var time = TimeSpan.FromMilliseconds(500); var time2 = TimeSpan.FromMilliseconds(250); var an = new DoubleAnimation(.95, 1, time) { EasingFunction = ease }; var an2 = new DoubleAnimation(0, 1, time2); RenderTransform.BeginAnimation(ScaleTransform.ScaleXProperty, an); BeginAnimation(OpacityProperty, an2); }
/// <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) { //check the animation clock event VerifyAnimationCompletedStatus(animationClock); //check if the animation was completed if (isCompleted) { return((GridLength)defaultDestinationValue); } //if not then create the value to animate double fromVal = this.From.Value; double toVal = this.To.Value; //check if the value is already collapsed if (((GridLength)defaultOriginValue).Value == toVal) { fromVal = toVal; toVal = this.ReverseValue; } else //check to see if this is the last tick of the animation clock. if (animationClock.CurrentProgress.Value == 1.0) { return(To); } EasingFunctionBase easing = new ElasticEase() { Oscillations = 2, EasingMode = EasingMode.EaseOut, Springiness = 10 }; if (fromVal > toVal) { return(new GridLength((1 - easing.Ease(animationClock.CurrentProgress.Value)) * (fromVal - toVal) + toVal, this.From.IsStar ? GridUnitType.Star : GridUnitType.Pixel)); } else { return(new GridLength(easing.Ease(animationClock.CurrentProgress.Value) * (toVal - fromVal) + fromVal, this.From.IsStar ? GridUnitType.Star : GridUnitType.Pixel)); } }
private void DoSomething() { //This will stop the classifier and it's also used in the keyEvent handler METState.Current.SCRL_State = METState.SCRL_States.stopped; double stopPos = _scroll.X; int indx = GetTargetIndex(stopPos); GetItemName(indx); if (METState.Current.demos_mode == METState.SCRL_demos.MindReading) { METState.Current.SCRL_State = METState.SCRL_States.Rolling; } else if (METState.Current.demos_mode != METState.SCRL_demos.MindReading)//Only for other demos { storyboard_scroll.Stop(); //storyboard_scroll.Children.Clear(); _scroll.X = stopPos; ElasticEase ease = new ElasticEase(); ease.EasingMode = EasingMode.EaseOut; ease.Oscillations = 2; ease.Springiness = 8; //finding the pos that brings the target in the middle of the screen double desiredPos = indx * (border_width + METState.Current.SCRL_image_width) + METState.Current.SCRL_window_W / 2 + border_width + METState.Current.SCRL_image_width / 2; desiredPos = -desiredPos; DoubleAnimation animation_scroll = new DoubleAnimation { Duration = TimeSpan.FromSeconds(1), From = stopPos, To = desiredPos, EasingFunction = ease }; Scroll(animation_scroll, false); } }
private Storyboard GetFadeAnimation(FrameworkElement target, bool forward) { RotateTransform st = new RotateTransform(); st.Angle = 360; Point p = new Point(0.5, 0.5); target.RenderTransformOrigin = p; target.RenderTransform = st; Storyboard sb = new Storyboard(); var duration = TimeSpan.FromSeconds(0.25); EasingFunctionBase easing = new ElasticEase() { EasingMode = EasingMode.EaseInOut, Oscillations = 20, Springiness = 5 }; DoubleAnimation da1 = new DoubleAnimation(); DoubleAnimation da2 = new DoubleAnimation(); if (forward) { da1.From = 1.0; da1.To = 0.0; da2.To = 1.0; } else { da1.From = 0.0; da1.To = 1.0; } da1.Duration = duration; da2.Duration = duration; da1.EasingFunction = easing; da2.EasingFunction = easing; sb.Children.Add(da1); sb.Children.Add(da2); Storyboard.SetTargetProperty(da2, new PropertyPath("RenderTransform.Angle")); Storyboard.SetTargetProperty(da1, new PropertyPath("Opacity")); return(sb); }
private void tbPositionTab_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { ElasticEase elasticEase = new ElasticEase(); elasticEase.Oscillations = 2; elasticEase.Springiness = 1; elasticEase.EasingMode = EasingMode.EaseOut; DoubleAnimation doubleAnimation = new DoubleAnimation() { Duration = TimeSpan.FromSeconds(1), EasingFunction = elasticEase }; if (sender == spPositionTab) { if (isBigPositionTab) { doubleAnimation.From = tbPositionTab.ActualWidth; doubleAnimation.To = ActualWidth / 8; } else { doubleAnimation.From = tbPositionTab.ActualWidth; doubleAnimation.To = tbPositionTab.ActualWidth * 2; } tbPositionTab.BeginAnimation(WidthProperty, doubleAnimation); isBigPositionTab = !isBigPositionTab; } else if (sender == spColorTab) { if (isBigColorTab) { doubleAnimation.From = tbColorTab.ActualWidth; doubleAnimation.To = ActualWidth / 8; } else { doubleAnimation.From = tbColorTab.ActualWidth; doubleAnimation.To = tbColorTab.ActualWidth * 2; } tbColorTab.BeginAnimation(WidthProperty, doubleAnimation); isBigColorTab = !isBigColorTab; } }
private void AnimateIndicator(double topMargin) { ElasticEase ea = new ElasticEase { EasingMode = EasingMode.EaseOut, Oscillations = 2, Springiness = 6 }; DoubleAnimation doubleAnim = new DoubleAnimation { From = Canvas.GetTop(rectangleSelectedPanel), To = topMargin, Duration = TimeSpan.FromMilliseconds(600), EasingFunction = ea }; rectangleSelectedPanel.BeginAnimation(Canvas.TopProperty, doubleAnim); Canvas.SetTop(rectangleSelectedPanel, topMargin); }
private void GetAnimation(Individual IndFromAlgorithm, int bias, double AnimTime, double AnimStart, bool EndOfGeneration, Ellipse El, TextBlock Number) { ElasticEase IFunc = new ElasticEase() { EasingMode = EasingMode.EaseInOut, Oscillations = 25, Springiness = 10 }; CircleEase IFunc1 = new CircleEase() { }; DoubleAnimation ElWAnimation = new DoubleAnimation()//формируем анимацию для появления эллипса { From = 35, To = 35, Duration = TimeSpan.FromSeconds(AnimTime), BeginTime = TimeSpan.FromSeconds(AnimStart * bias), EasingFunction = IFunc1 }; El.BeginAnimation(Ellipse.WidthProperty, ElWAnimation); if (EndOfGeneration)// если особь крайняя крепим за ней событие отбора { ElWAnimation.Completed += Killing; } El.BeginAnimation(Ellipse.HeightProperty, ElWAnimation); StringAnimationUsingKeyFrames NumAnimation = new StringAnimationUsingKeyFrames()//формируем анимацию для появления текста на эллипсе { Duration = TimeSpan.FromSeconds(0), BeginTime = TimeSpan.FromSeconds(AnimStart * bias), }; NumAnimation.KeyFrames.Add(new DiscreteStringKeyFrame() { Value = IndFromAlgorithm.x.ToString("F2") + "\n" + IndFromAlgorithm.y.ToString("F2"), KeyTime = KeyTime.FromPercent(1) }); Number.BeginAnimation(TextBlock.TextProperty, NumAnimation); }
private void CloseStoryboard() { _closeWindow = new Storyboard(); _closeWindow.Completed += _closeWindow_Completed; #region 创建关闭动画 DoubleAnimationUsingKeyFrames keyFrame1 = new DoubleAnimationUsingKeyFrames(); EasingDoubleKeyFrame ea = new EasingDoubleKeyFrame(1, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.0))); EasingDoubleKeyFrame ea1 = new EasingDoubleKeyFrame(0, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.5))); ElasticEase be = new ElasticEase(); be.EasingMode = EasingMode.EaseIn; be.Springiness = 5; be.Oscillations = 1; ea1.EasingFunction = be; keyFrame1.KeyFrames.Add(ea); keyFrame1.KeyFrames.Add(ea1); Storyboard.SetTarget(keyFrame1, grid); Storyboard.SetTargetProperty(keyFrame1, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)")); _closeWindow.Children.Add(keyFrame1); DoubleAnimationUsingKeyFrames keyFrame2 = new DoubleAnimationUsingKeyFrames(); ea = new EasingDoubleKeyFrame(1, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.0))); ea1 = new EasingDoubleKeyFrame(0, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.5))); be = new ElasticEase(); be.EasingMode = EasingMode.EaseIn; be.Springiness = 5; be.Oscillations = 1; ea1.EasingFunction = be; keyFrame2.KeyFrames.Add(ea); keyFrame2.KeyFrames.Add(ea1); Storyboard.SetTarget(keyFrame2, grid); Storyboard.SetTargetProperty(keyFrame2, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)")); _closeWindow.Children.Add(keyFrame2); #endregion _closeWindow.Begin(grid); }
private void WOnClosing(object Sender, CancelEventArgs E) { if (Sender is Window w && w.Template?.FindName("Transform", w) is ScaleTransform { ScaleX : 1.0 } sc) { E.Cancel = true; w.CacheMode = new BitmapCache(); DoubleAnimation a = new() { Duration = TimeSpan.FromSeconds(0.3), EasingFunction = new ElasticEase() { Oscillations = 1, EasingMode = EasingMode.EaseIn } }; a.Completed += (O, Args) => { w.Close(); }; sc.BeginAnimation(ScaleTransform.ScaleXProperty, a); } } }
/// <summary> /// The start animation. /// </summary> /// <param name="target"> /// The target. /// </param> /// <returns> /// The <see cref="Storyboard"/>. /// </returns> public override Storyboard GenerateAnimation(FrameworkElement target) { var ease = new ElasticEase { EasingMode = EasingMode.EaseInOut }; var doubleAnimation = new DoubleAnimation { From = 0, To = 800, Duration = TimeSpan.FromSeconds(5), EasingFunction = ease }; Storyboard.SetTarget(doubleAnimation, target); Storyboard.SetTargetProperty( doubleAnimation, "(FrameworkElement.RenderTransform).(TranslateTransform.X)"); var storyboard = new Storyboard(); storyboard.Children.Add(doubleAnimation); return(storyboard); }
public static void ScaleEasingAnimation(FrameworkElement element) { ScaleTransform scale = new ScaleTransform(); element.RenderTransform = scale; element.RenderTransformOrigin = new Point(0.5, 0.5);//定义圆心位置 EasingFunctionBase easing = new ElasticEase() { EasingMode = EasingMode.EaseOut, //公式 Oscillations = 1, //滑过动画目标的次数 Springiness = 10 //弹簧刚度 }; DoubleAnimation scaleAnimation = new DoubleAnimation() { From = 0, //起始值 To = 1, //结束值 EasingFunction = easing, //缓动函数 Duration = new TimeSpan(0, 0, 0, 1, 200) //动画播放时间 }; AnimationClock clock = scaleAnimation.CreateClock(); scale.ApplyAnimationClock(ScaleTransform.ScaleXProperty, clock); scale.ApplyAnimationClock(ScaleTransform.ScaleYProperty, clock); }
private void UpdateOpenStoryboard() { mainButtonOpenStoryboard = null; if (panel == null) { return; } var duration = mainButtonAnimationDuration / 2; var ease1 = new CubicEase() { EasingMode = EasingMode.EaseOut }; var ease2 = new ElasticEase() { Oscillations = 1, EasingMode = EasingMode.EaseOut }; var sb = new Storyboard(); var x = ActualWidth / 15; var y = -ActualHeight / 15; if (ItemsPosition == GooeyButtonItemsPosition.LeftTop) { x = -Math.Abs(x); y = -Math.Abs(y); } else if (ItemsPosition == GooeyButtonItemsPosition.RightTop) { x = Math.Abs(x); y = -Math.Abs(y); } else if (ItemsPosition == GooeyButtonItemsPosition.LeftBottom) { x = -Math.Abs(x); y = Math.Abs(y); } else if (ItemsPosition == GooeyButtonItemsPosition.RightBottom) { x = Math.Abs(x); y = Math.Abs(y); } var dax = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTarget(dax, BackgroundShapeTranslate); Storyboard.SetTargetProperty(dax, "X"); dax.Duration = TimeSpan.FromSeconds(mainButtonAnimationDuration); dax.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = TimeSpan.FromSeconds(mainButtonAnimationDuration / 3), Value = x, EasingFunction = ease1 }); dax.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = TimeSpan.FromSeconds(mainButtonAnimationDuration), Value = 0, EasingFunction = ease2 }); var day = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTarget(day, BackgroundShapeTranslate); Storyboard.SetTargetProperty(day, "Y"); day.Duration = TimeSpan.FromSeconds(mainButtonAnimationDuration); day.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = TimeSpan.FromSeconds(mainButtonAnimationDuration / 3), Value = y, EasingFunction = ease1 }); day.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = TimeSpan.FromSeconds(mainButtonAnimationDuration), Value = 0, EasingFunction = ease2 }); var baan = new DoubleAnimation(); Storyboard.SetTarget(baan, this); Storyboard.SetTargetProperty(baan, "BlurAmount"); baan.EnableDependentAnimation = true; baan.To = 0d; baan.Duration = TimeSpan.FromSeconds(0.3); baan.EasingFunction = new CircleEase() { EasingMode = EasingMode.EaseIn }; sb.Children.Add(dax); sb.Children.Add(day); //sb.Children.Add(wdax); //sb.Children.Add(wday); sb.Children.Add(baan); mainButtonOpenStoryboard = sb; }