private static void FillAnimation(DoubleAnimationUsingKeyFrames animation, TransitionType type, double from, double to, TimeSpan duration, double fps) { Equation equation = (Equation)Delegate.CreateDelegate(typeof(Equation), typeof(Equations).GetMethod(type.ToString())); double total = duration.TotalMilliseconds; double step = 1000D / (double)fps; // clear animation animation.KeyFrames.Clear(); for (double i = 0; i < total; i += step) { LinearDoubleKeyFrame frame = new LinearDoubleKeyFrame(); frame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(i)); frame.Value = equation(i, from, to - from, total); animation.KeyFrames.Add(frame); } // always add exact final key frame LinearDoubleKeyFrame finalFrame = new LinearDoubleKeyFrame(); finalFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(total)); finalFrame.Value = to; animation.KeyFrames.Add(finalFrame); }
/// <summary> /// Анимация изменения размера RenderTransform.Scale /// </summary> /// <param name="Element">Элемент интерфейса</param> /// <param name="ScaleX">Масштаб по X</param> /// <param name="ScaleY">Масштаб по Y</param> /// <param name="Time">Время анимации</param> public static void ScaleTo(FrameworkElement Element, double ScaleX, double ScaleY, int Time = 10, int Wait = 0) { LinearDoubleKeyFrame keyFrame1 = new LinearDoubleKeyFrame { Value = ScaleX, KeyTime = TimeSpan.FromMilliseconds(Time) }; LinearDoubleKeyFrame keyFrame2 = new LinearDoubleKeyFrame { Value = ScaleY, KeyTime = TimeSpan.FromMilliseconds(Time) }; var dub1 = new DoubleAnimationUsingKeyFrames(); var dub2 = new DoubleAnimationUsingKeyFrames(); Storyboard sb = new Storyboard(); dub1.KeyFrames.Add(keyFrame1); dub2.KeyFrames.Add(keyFrame2); sb.Children.Add(dub1); sb.Children.Add(dub2); Storyboard.SetTarget(dub1, Element); Storyboard.SetTarget(dub2, Element); Storyboard.SetTargetProperty(dub1, new PropertyPath("RenderTransform.ScaleX")); Storyboard.SetTargetProperty(dub2, new PropertyPath("RenderTransform.ScaleY")); sb.BeginTime = TimeSpan.FromMilliseconds(Wait); sb.Begin(); }
private void DisplayFadeMessage(String Message) { txtFadeMessage.Visibility = Visibility.Visible; txtFadeMessage.Text = Message; DoubleAnimationUsingKeyFrames _OpacityAnimation = new DoubleAnimationUsingKeyFrames(); DoubleKeyFrameCollection keyFrames = _OpacityAnimation.KeyFrames; LinearDoubleKeyFrame fr = new LinearDoubleKeyFrame(); fr.Value = 1; fr.KeyTime = TimeSpan.FromSeconds(0); keyFrames.Add(fr); LinearDoubleKeyFrame frEnd = new LinearDoubleKeyFrame(); frEnd.Value = 0.0; frEnd.KeyTime = TimeSpan.FromSeconds(3); keyFrames.Add(frEnd); ObjectAnimationUsingKeyFrames _VisibilityAnimation = new ObjectAnimationUsingKeyFrames(); DiscreteObjectKeyFrame frHide = new DiscreteObjectKeyFrame(); frHide.KeyTime = TimeSpan.FromSeconds(4); frHide.Value = Visibility.Collapsed; _VisibilityAnimation.KeyFrames.Add(frHide); Storyboard _Storyboard = new Storyboard(); _Storyboard.Children.Add(_OpacityAnimation); Storyboard.SetTargetProperty(_OpacityAnimation, "TextBlock.Opacity"); _Storyboard.Children.Add(_VisibilityAnimation); Storyboard.SetTargetProperty(_VisibilityAnimation, "TextBlock.Visibility"); Storyboard.SetTarget(_Storyboard, txtFadeMessage); _Storyboard.Begin(); }
void StoryLoad() { DoubleAnimationUsingKeyFrames daukf_img1 = new DoubleAnimationUsingKeyFrames(); LinearDoubleKeyFrame k1_img1 = new LinearDoubleKeyFrame(0.0, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2))); LinearDoubleKeyFrame k2_img1 = new LinearDoubleKeyFrame(-n_height, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(4))); daukf_img1.KeyFrames.Add(k1_img1); daukf_img1.KeyFrames.Add(k2_img1); storyboard_imgs.Children.Add(daukf_img1); Storyboard.SetTarget(daukf_img1, image1); Storyboard.SetTargetProperty(daukf_img1, new PropertyPath("(Canvas.Top)")); DoubleAnimationUsingKeyFrames daukf_img2 = new DoubleAnimationUsingKeyFrames(); LinearDoubleKeyFrame k1_img2 = new LinearDoubleKeyFrame(n_height, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2))); LinearDoubleKeyFrame k2_img2 = new LinearDoubleKeyFrame(0.0, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(4))); daukf_img2.KeyFrames.Add(k1_img2); daukf_img2.KeyFrames.Add(k2_img2); storyboard_imgs.Children.Add(daukf_img2); Storyboard.SetTarget(daukf_img2, image2); Storyboard.SetTargetProperty(daukf_img2, new PropertyPath("(Canvas.Top)")); storyboard_imgs.FillBehavior = FillBehavior.Stop; storyboard_imgs.Completed += new EventHandler(storyboard_imgs_Completed); storyboard_imgs.Begin(); }
internal void AddTranslateAnimations(Translatelist[] translateList) { if (translateList == null || translateList.Length <= 0) { return; } DoubleAnimationUsingKeyFrames dkX = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTargetName(dkX, "ttACP"); Storyboard.SetTargetProperty(dkX, new PropertyPath(TranslateTransform.XProperty)); _sbSRT.Children.Add(dkX); DoubleAnimationUsingKeyFrames dkY = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTargetName(dkY, "ttACP"); Storyboard.SetTargetProperty(dkY, new PropertyPath(TranslateTransform.YProperty)); _sbSRT.Children.Add(dkY); for (int i = 0; i < translateList.Length; i++) { LinearDoubleKeyFrame lpkX = new LinearDoubleKeyFrame(translateList[i].end_pos.X); lpkX.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(translateList[i].time)); dkX.KeyFrames.Add(lpkX); LinearDoubleKeyFrame lpkY = new LinearDoubleKeyFrame(translateList[i].end_pos.Y); lpkY.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(translateList[i].time)); dkY.KeyFrames.Add(lpkY); } StageMgr.Instance.UpdateMaxRecordDuration(translateList[translateList.Length - 1].time); }
public SmoothScrollViewer() { initFrame = new DiscreteDoubleKeyFrame() { KeyTime = TimeSpan.Zero }; beginFrame = new LinearDoubleKeyFrame() { KeyTime = TimeSpan.FromMilliseconds(60) }; endFrame = new LinearDoubleKeyFrame() { KeyTime = TimeSpan.FromMilliseconds(150) }; scrollFrames = new DoubleAnimationUsingKeyFrames(); scrollFrames.KeyFrames.Add(initFrame); scrollFrames.KeyFrames.Add(beginFrame); scrollFrames.KeyFrames.Add(endFrame); scrollStoryboard = new Storyboard(); scrollStoryboard.Children.Add(scrollFrames); Storyboard.SetTarget(scrollFrames, this); Storyboard.SetTargetProperty(scrollFrames, new PropertyPath(SmoothScrollViewer.OffsetProperty)); scrollStoryboard.Completed += OnStoryboardCompleted; }
private static DoubleKeyFrame CreateDoubleKeyFrmas(KeyFrames <double> Model) { DoubleKeyFrame frame = null; switch (Model.Type) { case KeyFramesType.Spline: frame = new SplineDoubleKeyFrame() { KeySpline = Model.Spline }; break; case KeyFramesType.Linear: frame = new LinearDoubleKeyFrame(); break; case KeyFramesType.Easing: frame = new EasingDoubleKeyFrame() { EasingFunction = Model.EasingFunction }; break; case KeyFramesType.Discrete: frame = new DiscreteDoubleKeyFrame(); break; default: break; } frame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(Model.KeyTime)); frame.Value = Model.Value; return(frame); }
private DoubleAnimationUsingKeyFrames MakeKeyanim(double _time, double _delay, double _value, double _pre1, double _pre2) { DoubleAnimationUsingKeyFrames Anim = new DoubleAnimationUsingKeyFrames(); Anim.Duration = new Duration(TimeSpan.FromSeconds(_time)); LinearDoubleKeyFrame Anim_kf_1 = new LinearDoubleKeyFrame(); LinearDoubleKeyFrame Anim_kf_2 = new LinearDoubleKeyFrame(); LinearDoubleKeyFrame Anim_kf_3 = new LinearDoubleKeyFrame(); LinearDoubleKeyFrame Anim_kf_4 = new LinearDoubleKeyFrame(); Anim_kf_1.KeyTime = KeyTime.FromPercent(0); Anim_kf_1.Value = 0.0; Anim_kf_2.KeyTime = KeyTime.FromPercent(_pre1); Anim_kf_2.Value = _value; Anim_kf_3.KeyTime = KeyTime.FromPercent(_pre2); Anim_kf_3.Value = _value; Anim_kf_4.KeyTime = KeyTime.FromPercent(1); Anim_kf_4.Value = 0.0; Anim.KeyFrames.Add(Anim_kf_1); Anim.KeyFrames.Add(Anim_kf_2); Anim.KeyFrames.Add(Anim_kf_3); Anim.KeyFrames.Add(Anim_kf_4); Anim.BeginTime = TimeSpan.FromSeconds(_delay); Anim.RepeatBehavior = RepeatBehavior.Forever; return(Anim); }
private void ChangeGridWidth(Grid grid, int oldWidth, int newWidth, TimeSpan duration) { DoubleAnimationUsingKeyFrames animation = new DoubleAnimationUsingKeyFrames(); LinearDoubleKeyFrame start = new LinearDoubleKeyFrame(oldWidth); animation.KeyFrames.Add(start); LinearDoubleKeyFrame end = new LinearDoubleKeyFrame(newWidth, duration); animation.KeyFrames.Add(end); grid.BeginAnimation(Grid.WidthProperty, animation); }
public static DoubleAnimationUsingKeyFrames CreateStandardKeyFrames(DependencyObject dependencyObject, string propertyName, double defaultValue, double startValue, double endValue, double duration, double staggerDelay) { // total duration double totalDuration = duration + staggerDelay; // create the key frames holder DoubleAnimationUsingKeyFrames frames = new DoubleAnimationUsingKeyFrames() { Duration = TimeSpan.FromMilliseconds(totalDuration), EnableDependentAnimation = true }; // set the target Storyboard.SetTarget(frames, dependencyObject); Storyboard.SetTargetProperty(frames, propertyName); // create frame 0; if we have a stagger delay, then create this frame with the default value LinearDoubleKeyFrame _frame0 = new LinearDoubleKeyFrame() { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0d)), Value = (staggerDelay > 0) ? defaultValue : startValue }; frames.KeyFrames.Add(_frame0); // if we have a stagger delay if (staggerDelay > 0) { // create stagger frame LinearDoubleKeyFrame _frameStagger = new LinearDoubleKeyFrame() { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(staggerDelay)), Value = startValue }; frames.KeyFrames.Add(_frameStagger); } // create frame 1 LinearDoubleKeyFrame _frame1 = new LinearDoubleKeyFrame() { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(totalDuration)), Value = endValue }; frames.KeyFrames.Add(_frame1); // set the target Storyboard.SetTarget(frames, dependencyObject); Storyboard.SetTargetProperty(frames, propertyName); return(frames); }
/// <summary> /// 获取动画中Double类型属性的关键帧组 /// </summary> /// <param name="from">初始值</param> /// <param name="to">目标值</param> /// <param name="obj">动画控件</param> /// <param name="path">动画属性</param> /// <returns>关键帧组</returns> DoubleAnimationUsingKeyFrames getDAUKF(double from, double to, DependencyObject obj, PropertyPath path) { DoubleAnimationUsingKeyFrames daukf = new DoubleAnimationUsingKeyFrames(); LinearDoubleKeyFrame k1 = new LinearDoubleKeyFrame(from, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(this.TimeHold))); LinearDoubleKeyFrame k2 = new LinearDoubleKeyFrame(to, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(this.TimeHold + this.TimeChange))); daukf.KeyFrames.Add(k1); daukf.KeyFrames.Add(k2); Storyboard.SetTarget(daukf, obj); Storyboard.SetTargetProperty(daukf, path); return(daukf); }
private async void Weather_ManipulationDelta(object sender, Windows.UI.Xaml.Input.ManipulationDeltaRoutedEventArgs e) { if (e.IsInertial && !_isSwiped && !_animationRunning) { var distance = e.Cumulative.Translation.X; if (Math.Abs(distance) <= 2) { return; } _isSwiped = true; var translateTransform = CurrentWeatherGrid.RenderTransform = new TranslateTransform(); Storyboard storyboard = new Storyboard(); DoubleAnimationUsingKeyFrames animationKeyFrames = new DoubleAnimationUsingKeyFrames(); var keyFrame = new LinearDoubleKeyFrame(); keyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(750)); keyFrame.Value = distance > 0 ? ActualWidth : -ActualWidth; animationKeyFrames.KeyFrames.Add(keyFrame); keyFrame = new LinearDoubleKeyFrame(); keyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(751)); keyFrame.Value = distance > 0 ? -ActualWidth : ActualWidth; animationKeyFrames.KeyFrames.Add(keyFrame); keyFrame = new LinearDoubleKeyFrame(); keyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(1500)); keyFrame.Value = 0; animationKeyFrames.KeyFrames.Add(keyFrame); Storyboard.SetTargetProperty(animationKeyFrames, "X"); Storyboard.SetTarget(animationKeyFrames, translateTransform); storyboard.Children.Add(animationKeyFrames); storyboard.Completed += Animation_Completed; _animationRunning = true; storyboard.Begin(); await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { await Task.Delay(751); if (distance > 0) { _viewModel.SwitchDay(false); } else { _viewModel.SwitchDay(true); } }); } }
public static DoubleAnimationUsingKeyFrames MoveVerticalAnimationUsingKeyFrames(double y, double dy, int durationInSeconds = 0) { var animation = new DoubleAnimationUsingKeyFrames(); var keyFrameStart = new LinearDoubleKeyFrame(y, KeyTime.FromPercent(0)); var keyFrameFinish = new LinearDoubleKeyFrame(y + dy, KeyTime.FromPercent(100)); animation.KeyFrames = new DoubleKeyFrameCollection { keyFrameStart, keyFrameFinish }; animation.Duration = new Duration(TimeSpan.FromSeconds(durationInSeconds)); return(animation); }
/// <summary> /// 更新路径 /// </summary> protected void RunPath(Path path, double MilliSecond = 1000) { if (!this.IsUseAnimation) { return; } double _pathLength = path.Data.GetTotalLength(new Size(path.ActualWidth, path.ActualHeight), path.StrokeThickness) * 2; if (Math.Abs(_pathLength) < 1E-06) { return; } path.StrokeDashOffset = _pathLength; path.StrokeDashArray = new DoubleCollection(new List <double> { _pathLength, _pathLength }); //定义动画 if (_storyboard != null) { _storyboard.Stop(); } _storyboard = new Storyboard(); var frames = new DoubleAnimationUsingKeyFrames(); var frame0 = new LinearDoubleKeyFrame { Value = _pathLength, KeyTime = KeyTime.FromTimeSpan(TimeSpan.Zero) }; var frame1 = new LinearDoubleKeyFrame { Value = 0, KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(MilliSecond)) }; frames.KeyFrames.Add(frame0); frames.KeyFrames.Add(frame1); Storyboard.SetTarget(frames, path); Storyboard.SetTargetProperty(frames, new PropertyPath(Path.StrokeDashOffsetProperty)); _storyboard.Children.Add(frames); _storyboard.Begin(); }
/// <summary> /// /// </summary> /// <param name="camera"></param> /// <param name="animationKeyFrames"></param> /// <param name="animationKeyFramesCameraPosition"></param> /// <param name="animationKeyFramesCameraLookDirection"></param> private void ApplyAnimation(Point3DAnimationUsingKeyFrames animationKeyFrames, Point3DAnimationUsingKeyFrames animationKeyFramesCameraPosition, Vector3DAnimationUsingKeyFrames animationKeyFramesCameraLookDirection, DoubleAnimationUsingKeyFrames animationKeyFramesFieldofView) { double factor = 5; List <Cube> cubeCollection = CalculateDistance(camera); for (int i = 0; i < cubeCollection.Count; i++) { DoubleAnimationUsingKeyFrames opacitykeyFrame = new DoubleAnimationUsingKeyFrames(); double oldOpacity = 0; double newOpacity; double delta = 0; if ((cubeCollection[i].NewDistanceFromViewer - cubeCollection[i].OldDistanceFromViewer) > 0) { oldOpacity = .8; delta = (.1) / factor; } else { oldOpacity = 1; delta = -(.2) / factor; } for (int count = 1; count < factor; count++) { newOpacity = oldOpacity + delta * count; if (newOpacity > 0 && newOpacity <= 1) { LinearDoubleKeyFrame linearkeyFrame = new LinearDoubleKeyFrame(newOpacity); opacitykeyFrame.KeyFrames.Add(linearkeyFrame); } } cubeCollection[i].BeginAnimation(Cube.opacityProperty, opacitykeyFrame, HandoffBehavior.SnapshotAndReplace); } Magnet.BeginAnimation(Cube.StartingPointCubeProperty, animationKeyFrames, HandoffBehavior.Compose); this.ViewModelCamera.BeginAnimation(PerspectiveCamera.PositionProperty, animationKeyFramesCameraPosition, HandoffBehavior.Compose); this.ViewModelCamera.BeginAnimation(PerspectiveCamera.LookDirectionProperty, animationKeyFramesCameraLookDirection, HandoffBehavior.Compose); this.ViewModelCamera.BeginAnimation(PerspectiveCamera.FieldOfViewProperty, animationKeyFramesFieldofView, HandoffBehavior.Compose); this.cubeAnimationCompleted = false; this.positionAnimationCompleted = false; this.cameraLookdirectionAnimationCompleted = false; this.fieldViewAnimationCompleted = false; }
private void btn_move_Click(object sender, RoutedEventArgs e) { //声明关键帧动画属性实例 DoubleAnimationUsingKeyFrames dukX = new DoubleAnimationUsingKeyFrames(); DoubleAnimationUsingKeyFrames dukY = new DoubleAnimationUsingKeyFrames(); //设置动画总时长 dukX.Duration = new Duration(TimeSpan.FromMilliseconds(900)); dukY.Duration = new Duration(TimeSpan.FromMilliseconds(900)); //创建,添添加关键帧 LinearDoubleKeyFrame x_kf_1 = new LinearDoubleKeyFrame(); LinearDoubleKeyFrame x_kf_2 = new LinearDoubleKeyFrame(); LinearDoubleKeyFrame x_kf_3 = new LinearDoubleKeyFrame(); //添加X属性关键帧 x_kf_1.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(300)); x_kf_1.Value = 200; x_kf_2.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(600)); x_kf_2.Value = 0; x_kf_3.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(900)); x_kf_3.Value = 200; dukX.KeyFrames.Add(x_kf_1); dukX.KeyFrames.Add(x_kf_2); dukX.KeyFrames.Add(x_kf_3); //添加Y属性关键帧 //创建,添添加关键帧 LinearDoubleKeyFrame y_kf_1 = new LinearDoubleKeyFrame(); LinearDoubleKeyFrame y_kf_2 = new LinearDoubleKeyFrame(); LinearDoubleKeyFrame y_kf_3 = new LinearDoubleKeyFrame(); y_kf_1.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(300)); y_kf_1.Value = 0; y_kf_2.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(600)); y_kf_2.Value = 180; y_kf_3.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(900)); y_kf_3.Value = 180; dukY.KeyFrames.Add(y_kf_1); dukY.KeyFrames.Add(y_kf_2); dukY.KeyFrames.Add(y_kf_3); //执行动画 tt_demo.BeginAnimation(TranslateTransform.XProperty, dukX); tt_demo.BeginAnimation(TranslateTransform.YProperty, dukY); }
protected override void OnApplyTemplate() { base.OnApplyTemplate(); _selectionIndicator = GetTemplateChild(SelectionIndicatorName) as UIElement; _selectionIndicatorScaleFrame = GetTemplateChild(SelectionIndicatorScaleFrameName) as EasingDoubleKeyFrame; _selectionIndicatorStoryboard = GetTemplateChild(SelectionIndicatorAnimationName) as Storyboard; _selectionIndicatorFadeStoryboard = GetTemplateChild(SelectionIndicatorFadeAnimationName) as Storyboard; _selectionIndicatorTranslateStartFrame = GetTemplateChild(SelectionIndicatorTranslateStartFrameName) as DiscreteDoubleKeyFrame; _selectionIndicatorTranslateEndFrame = GetTemplateChild(SelectionIndicatorTranslateEndFrameName) as LinearDoubleKeyFrame; _selectionIndicatorTransform = GetTemplateChild(SelectionIndicatorTransformName) as CompositeTransform; _selectionIndicatorCenterStartFrame = GetTemplateChild(SelectionIndicatorCenterStartFrameName) as DiscreteDoubleKeyFrame; _selectionIndicatorCenterEndFrame = GetTemplateChild(SelectionIndicatorCenterEndFrameName) as LinearDoubleKeyFrame; UpdateLocalVisualState(); }
private void storyboardAnimationFromFile() { licznik_punktow_animacji = 0; SeriesCollection[0].Values.Clear(); SeriesCollection[1].Values.Clear(); SeriesCollection[2].Values.Clear(); var xDoubleAnimationUsingKeyFrames = new DoubleAnimationUsingKeyFrames(); var yDoubleAnimationUsingKeyFrames = new DoubleAnimationUsingKeyFrames(); var zDoubleAnimationUsingKeyFrames = new DoubleAnimationUsingKeyFrames(); int czas = 0; foreach (var coord in myAnimationCoords) { var xkeyFrame = new LinearDoubleKeyFrame(); var ykeyFrame = new LinearDoubleKeyFrame(); var zkeyFrame = new LinearDoubleKeyFrame(); xkeyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(czas)); xkeyFrame.Value = coord.x; ykeyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(czas)); ykeyFrame.Value = coord.y; zkeyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(czas)); zkeyFrame.Value = coord.z; xDoubleAnimationUsingKeyFrames.KeyFrames.Add(xkeyFrame); yDoubleAnimationUsingKeyFrames.KeyFrames.Add(ykeyFrame); zDoubleAnimationUsingKeyFrames.KeyFrames.Add(zkeyFrame); czas += 1; } Storyboard.SetTargetName(xDoubleAnimationUsingKeyFrames, "myTranslateTransform"); Storyboard.SetTargetProperty(xDoubleAnimationUsingKeyFrames, new PropertyPath(TranslateTransform3D.OffsetXProperty)); Storyboard.SetTargetName(yDoubleAnimationUsingKeyFrames, "myTranslateTransform"); Storyboard.SetTargetProperty(yDoubleAnimationUsingKeyFrames, new PropertyPath(TranslateTransform3D.OffsetYProperty)); Storyboard.SetTargetName(zDoubleAnimationUsingKeyFrames, "myTranslateTransform"); Storyboard.SetTargetProperty(zDoubleAnimationUsingKeyFrames, new PropertyPath(TranslateTransform3D.OffsetZProperty)); sb.Children.Add(xDoubleAnimationUsingKeyFrames); sb.Children.Add(yDoubleAnimationUsingKeyFrames); sb.Children.Add(zDoubleAnimationUsingKeyFrames); sb.Completed += sb_Completed; sb.Begin(this, true); }
private async void Weather_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e) { if (sender is FrameworkElement f && f.DataContext is WeatherWrapper weather) { if (!_animationRunning) { var scaleTransform = CurrentWeatherGrid.RenderTransform = new ScaleTransform(); Storyboard storyboard = new Storyboard(); DoubleAnimationUsingKeyFrames animationKeyFrames = new DoubleAnimationUsingKeyFrames(); var keyFrame = new LinearDoubleKeyFrame(); keyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(1)); keyFrame.Value = 0.1; animationKeyFrames.KeyFrames.Add(keyFrame); keyFrame = new LinearDoubleKeyFrame(); keyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(500)); keyFrame.Value = 1; animationKeyFrames.KeyFrames.Add(keyFrame); Storyboard.SetTargetProperty(animationKeyFrames, "ScaleX"); Storyboard.SetTarget(animationKeyFrames, scaleTransform); storyboard.Children.Add(animationKeyFrames); var animationKeyFramesY = new DoubleAnimationUsingKeyFrames(); keyFrame = new LinearDoubleKeyFrame(); keyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(1)); keyFrame.Value = 0.1; animationKeyFramesY.KeyFrames.Add(keyFrame); keyFrame = new LinearDoubleKeyFrame(); keyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(500)); keyFrame.Value = 1; animationKeyFramesY.KeyFrames.Add(keyFrame); Storyboard.SetTargetProperty(animationKeyFramesY, "ScaleY"); Storyboard.SetTarget(animationKeyFramesY, scaleTransform); storyboard.Children.Add(animationKeyFramesY); storyboard.Completed += Animation_Completed; _animationRunning = true; storyboard.Begin(); await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { await Task.Delay(50); _viewModel.CurrentWeather = weather; }); } } }
public static Timeline CreateKeyFrameAnimation(this Storyboard storyboard, IList <double> values, IList <Duration> times) { var keyFrameAnimation = new DoubleAnimationUsingKeyFrames(); var keyTime = TimeSpan.FromMilliseconds(0); for (var i = 0; i < values.Count(); i++) { keyTime += times[i].TimeSpan; var frame = new LinearDoubleKeyFrame { Value = values[i], KeyTime = keyTime }; keyFrameAnimation.KeyFrames.Add(frame); keyFrameAnimation.Duration += times[i]; } return(keyFrameAnimation); }
void StoryLoad() { DoubleAnimationUsingKeyFrames daukf_img1 = new DoubleAnimationUsingKeyFrames(); LinearDoubleKeyFrame k1_img1 = new LinearDoubleKeyFrame(0.0, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0))); LinearDoubleKeyFrame k2_img1 = new LinearDoubleKeyFrame(-100, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(3))); daukf_img1.KeyFrames.Add(k1_img1); daukf_img1.KeyFrames.Add(k2_img1); storyboard_imgs.Children.Add(daukf_img1); Storyboard.SetTarget(daukf_img1, image1); Storyboard.SetTargetProperty(daukf_img1, new PropertyPath("(Canvas.Left)")); DoubleAnimationUsingKeyFrames daukf_img2 = new DoubleAnimationUsingKeyFrames(); LinearDoubleKeyFrame k1_img2 = new LinearDoubleKeyFrame(100.0, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0))); LinearDoubleKeyFrame k2_img2 = new LinearDoubleKeyFrame(0.0, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(3))); daukf_img2.KeyFrames.Add(k1_img2); daukf_img2.KeyFrames.Add(k2_img2); storyboard_imgs.Children.Add(daukf_img2); Storyboard.SetTarget(daukf_img2, image2); Storyboard.SetTargetProperty(daukf_img2, new PropertyPath("(Canvas.Left)")); DoubleAnimationUsingKeyFrames daukf_img3 = new DoubleAnimationUsingKeyFrames(); LinearDoubleKeyFrame k1_img3 = new LinearDoubleKeyFrame(200.0, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0))); LinearDoubleKeyFrame k2_img3 = new LinearDoubleKeyFrame(100.0, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(3))); daukf_img3.KeyFrames.Add(k1_img3); daukf_img3.KeyFrames.Add(k2_img3); storyboard_imgs.Children.Add(daukf_img3); Storyboard.SetTarget(daukf_img3, image3); Storyboard.SetTargetProperty(daukf_img3, new PropertyPath("(Canvas.Left)")); DoubleAnimationUsingKeyFrames daukf_img4 = new DoubleAnimationUsingKeyFrames(); LinearDoubleKeyFrame k1_img4 = new LinearDoubleKeyFrame(300.0, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0))); LinearDoubleKeyFrame k2_img4 = new LinearDoubleKeyFrame(200.0, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(3))); daukf_img4.KeyFrames.Add(k1_img4); daukf_img4.KeyFrames.Add(k2_img4); storyboard_imgs.Children.Add(daukf_img4); Storyboard.SetTarget(daukf_img4, image4); Storyboard.SetTargetProperty(daukf_img4, new PropertyPath("(Canvas.Left)")); storyboard_imgs.FillBehavior = FillBehavior.Stop; storyboard_imgs.Completed += new EventHandler(storyboard_imgs_Completed); storyboard_imgs.Begin(); }
public static void DoubleAnimation(Storyboard Board, DependencyObject Element, string Property, double From, double To, double Duration = 350, double Delay = 0, EasingFunctionBase Easing = null) { DoubleAnimationUsingKeyFrames d = new DoubleAnimationUsingKeyFrames(); if (Easing == null) { Easing = new CubicEase() { EasingMode = EasingMode.EaseOut } } ; EasingDoubleKeyFrame still = new EasingDoubleKeyFrame(); still.Value = From; still.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)); still.EasingFunction = Easing; if (0 < Delay) { LinearDoubleKeyFrame still_still = new LinearDoubleKeyFrame(); still_still.Value = From; still_still.KeyTime = still.KeyTime; still.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(Delay)); d.KeyFrames.Add(still_still); } EasingDoubleKeyFrame move = new EasingDoubleKeyFrame(); move.Value = To; move.EasingFunction = Easing; move.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(Delay + Duration)); d.Duration = new Duration(TimeSpan.FromMilliseconds(Delay + Duration)); d.KeyFrames.Add(still); d.KeyFrames.Add(move); Storyboard.SetTarget(d, Element); Storyboard.SetTargetProperty(d, new PropertyPath(Property)); Board.Children.Add(d); }
internal void AddOpacityAnimations(Opacitylist[] opacityList) { if (opacityList == null || opacityList.Length <= 0) { return; } DoubleAnimationUsingKeyFrames dk = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTargetProperty(dk, new PropertyPath("Opacity")); _sbOpacity.Children.Add(dk); for (int i = 0; i < opacityList.Length; i++) { LinearDoubleKeyFrame lpk = new LinearDoubleKeyFrame(opacityList[i].end_opacity); lpk.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(opacityList[i].time)); dk.KeyFrames.Add(lpk); } StageMgr.Instance.UpdateMaxRecordDuration(opacityList[opacityList.Length - 1].time); }
private void StartAnimation() { Storyboard board = new Storyboard(); var timeline = new DoubleAnimationUsingKeyFrames(); timeline.RepeatBehavior = RepeatBehavior.Forever; Storyboard.SetTarget(timeline, rotateTransform); Storyboard.SetTargetProperty(timeline, new PropertyPath("Angle")); var frame = new LinearDoubleKeyFrame() { KeyTime = TimeSpan.FromSeconds(1), Value = 360 }; timeline.KeyFrames.Add(frame); board.Children.Add(timeline); board.Begin(); }
private void Button_Click_1(object sender, RoutedEventArgs e) { DoubleAnimationUsingKeyFrames dakX = new DoubleAnimationUsingKeyFrames(); DoubleAnimationUsingKeyFrames dakY = new DoubleAnimationUsingKeyFrames(); //设置动画时长 dakX.Duration = new Duration(TimeSpan.FromMilliseconds(2000)); dakX.Duration = new Duration(TimeSpan.FromMilliseconds(2000)); //创建、添加关键帧 LinearDoubleKeyFrame x_kf_1 = new LinearDoubleKeyFrame(); LinearDoubleKeyFrame x_kf_2 = new LinearDoubleKeyFrame(); LinearDoubleKeyFrame x_kf_3 = new LinearDoubleKeyFrame(); x_kf_1.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(300)); x_kf_1.Value = 200; x_kf_2.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(600)); x_kf_2.Value = 0; x_kf_3.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(900)); x_kf_3.Value = 200; dakX.KeyFrames.Add(x_kf_1); dakX.KeyFrames.Add(x_kf_2); dakX.KeyFrames.Add(x_kf_3); LinearDoubleKeyFrame y_kf_1 = new LinearDoubleKeyFrame(); LinearDoubleKeyFrame y_kf_2 = new LinearDoubleKeyFrame(); LinearDoubleKeyFrame y_kf_3 = new LinearDoubleKeyFrame(); y_kf_1.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(300)); y_kf_1.Value = 200; y_kf_2.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(600)); y_kf_2.Value = 0; y_kf_3.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(900)); y_kf_3.Value = 200; dakY.KeyFrames.Add(y_kf_1); dakY.KeyFrames.Add(y_kf_2); dakY.KeyFrames.Add(y_kf_3); //执行动画 t2.BeginAnimation(TranslateTransform.XProperty, dakX); t2.BeginAnimation(TranslateTransform.YProperty, dakY); }
private static void GridScaleOpacity(Grid ParentGrid, double Val1, double Val2, double Opacity, int Time1, int Time2, int OpacityTime, EventHandler OnStop = null) { LinearDoubleKeyFrame keyFrame1 = new LinearDoubleKeyFrame { Value = Val1, KeyTime = TimeSpan.FromMilliseconds(Time1) }; LinearDoubleKeyFrame keyFrame2 = new LinearDoubleKeyFrame { Value = Val2, KeyTime = TimeSpan.FromMilliseconds(Time2) }; LinearDoubleKeyFrame keyFrameOp = new LinearDoubleKeyFrame { Value = Opacity, KeyTime = TimeSpan.FromMilliseconds(OpacityTime) }; var dub1 = new DoubleAnimationUsingKeyFrames(); var dub2 = new DoubleAnimationUsingKeyFrames(); var dubOp = new DoubleAnimationUsingKeyFrames(); Storyboard sb = new Storyboard(); dub1.KeyFrames.Add(keyFrame1); dub1.KeyFrames.Add(keyFrame2); dub2.KeyFrames.Add(keyFrame1); dub2.KeyFrames.Add(keyFrame2); dubOp.KeyFrames.Add(keyFrameOp); sb.Children.Add(dub1); sb.Children.Add(dub2); sb.Children.Add(dubOp); Storyboard.SetTarget(dub1, ParentGrid); Storyboard.SetTarget(dub2, ParentGrid); Storyboard.SetTarget(dubOp, ParentGrid); Storyboard.SetTargetProperty(dub1, new PropertyPath("RenderTransform.ScaleX")); Storyboard.SetTargetProperty(dub2, new PropertyPath("RenderTransform.ScaleY")); Storyboard.SetTargetProperty(dubOp, new PropertyPath("Opacity")); if (OnStop != null) { sb.Completed += OnStop; } sb.Begin(); }
internal void AddRotationAnimations(Rotationlist[] rotationList) { if (rotationList == null || rotationList.Length <= 0) { return; } DoubleAnimationUsingKeyFrames dk = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTargetName(dk, "rtACP"); Storyboard.SetTargetProperty(dk, new PropertyPath(RotateTransform.AngleProperty)); _sbSRT.Children.Add(dk); for (int i = 0; i < rotationList.Length; i++) { LinearDoubleKeyFrame lpk = new LinearDoubleKeyFrame(rotationList[i].end_angle); lpk.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(rotationList[i].time)); dk.KeyFrames.Add(lpk); } StageMgr.Instance.UpdateMaxRecordDuration(rotationList[rotationList.Length - 1].time); }
public override void OnApplyTemplate() { base.OnApplyTemplate(); var rootGrid = GetTemplateChild("Root") as Grid; if (rootGrid != null) { for (int i = 0; i < 5; i++) { var d = new System.Windows.Shapes.Rectangle(); var tf = new TranslateTransform(); tf.X = -(PointSize); d.Fill = PointColor; d.Width = PointSize; d.Height = PointSize; d.RadiusX = PointRadius; d.RadiusY = PointRadius; d.HorizontalAlignment = HorizontalAlignment.Left; d.RenderTransform = tf; rectangles.Add(d); rootGrid.Children.Add(d); DoubleAnimationUsingKeyFrames db = new DoubleAnimationUsingKeyFrames(); db.BeginTime = TimeSpan.FromSeconds(i * PointPlayInterval); var ldkf1 = new LinearDoubleKeyFrame(0, TimeSpan.FromSeconds(0)); var ldkf2 = new LinearDoubleKeyFrame(0, TimeSpan.FromSeconds(0.5)); var ldkf3 = new LinearDoubleKeyFrame(0, TimeSpan.FromSeconds(2)); var ldkf4 = new LinearDoubleKeyFrame(0, TimeSpan.FromSeconds(2.5)); db.KeyFrames.Add(ldkf1); db.KeyFrames.Add(ldkf2); db.KeyFrames.Add(ldkf3); db.KeyFrames.Add(ldkf4); Storyboard.SetTarget(db, rectangles[i]); Storyboard.SetTargetProperty(db, new PropertyPath("RenderTransform.X")); storyboard.Children.Add(db); linearDoubleKeyFrames.Add(i, new List <LinearDoubleKeyFrame>() { ldkf1, ldkf2, ldkf3, ldkf4 }); } } }
public PopupMsg(TextBlock msg) { //Store TextBlock for message display this.msg = msg; //Register the textblock's name, this is necessary for creating Storyboard using codes instead of XAML NameScope.SetNameScope(msg, new NameScope()); msg.RegisterName("fadetext", msg); //Create the fade in & fade out animation DoubleAnimationUsingKeyFrames fadeInOutAni = new DoubleAnimationUsingKeyFrames(); LinearDoubleKeyFrame keyframe = new LinearDoubleKeyFrame(); keyframe.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2)); keyframe.Value = 1; fadeInOutAni.KeyFrames.Add(keyframe); //keyframe = new LinearDoubleKeyFrame(); fadeInOutAni.Duration = new Duration(TimeSpan.FromSeconds(4)); fadeInOutAni.AutoReverse = true; fadeInOutAni.AccelerationRatio = .2; fadeInOutAni.DecelerationRatio = .7; // Configure the animation to target the message's opacity property Storyboard.SetTargetName(fadeInOutAni, "fadetext"); Storyboard.SetTargetProperty(fadeInOutAni, new PropertyPath(TextBlock.OpacityProperty)); // Add the fade in & fade out animation to the Storyboard Storyboard fadeInOutStoryBoard = new Storyboard(); fadeInOutStoryBoard.Children.Add(fadeInOutAni); // Set event trigger, make this animation played on an event we can control msg.IsVisibleChanged += delegate(object sender, System.Windows.DependencyPropertyChangedEventArgs e) { if (msg.IsVisible) { fadeInOutStoryBoard.Begin(msg); } }; }
private void Button_Click_12(object sender, RoutedEventArgs e) { if (tflag) { sb.SkipToFill(); } else { sb = new Storyboard(); var transform = (this.ST3D_Background_Fore.Transform as Transform3DGroup).Children.First(t => t is TranslateTransform3D); dakfx = new DoubleAnimationUsingKeyFrames(); dakfy = new DoubleAnimationUsingKeyFrames(); var rand = new Random(); for (int i = 0; i < 50; i++) { var dx = rand.NextDouble() * (rand.Next(0, 100) >= 50 ? 1 : -1); var dy = rand.NextDouble() * (rand.Next(0, 100) <= 50 ? 1 : -1); LinearDoubleKeyFrame dkfx = new LinearDoubleKeyFrame(dx, TimeSpan.FromMilliseconds(50 * (i + 1))); LinearDoubleKeyFrame dkfy = new LinearDoubleKeyFrame(dy, TimeSpan.FromMilliseconds(50 * (i + 1))); dakfx.KeyFrames.Add(dkfx); dakfy.KeyFrames.Add(dkfy); } dakfx.RepeatBehavior = RepeatBehavior.Forever; dakfy.RepeatBehavior = RepeatBehavior.Forever; dakfx.Duration = TimeSpan.FromMilliseconds(50 * 50); dakfy.Duration = TimeSpan.FromMilliseconds(50 * 50); //this.ST3D_Camera.BeginAnimation(PerspectiveCamera.PositionProperty, dakf); Storyboard.SetTarget(dakfx, transform); //动画的对象 Storyboard.SetTargetProperty(dakfx, new PropertyPath(TranslateTransform3D.OffsetXProperty)); sb.Duration = TimeSpan.FromMilliseconds(50 * 50); sb.Children.Add(dakfx); sb.Begin(); //transform.BeginAnimation(TranslateTransform3D.OffsetXProperty, dakfx); //transform.BeginAnimation(TranslateTransform3D.OffsetYProperty, dakfy); } tflag = !tflag; }
public static Timeline CreateKeyFrameAnimation(this Storyboard storyboard, IList<double> values, IList<Duration> times) { var keyFrameAnimation = new DoubleAnimationUsingKeyFrames(); var keyTime = TimeSpan.FromMilliseconds(0); for (var i = 0; i < values.Count(); i++) { keyTime += times[i].TimeSpan; var frame = new LinearDoubleKeyFrame { Value = values[i], KeyTime = keyTime }; keyFrameAnimation.KeyFrames.Add(frame); keyFrameAnimation.Duration += times[i]; } return keyFrameAnimation; }