public void PlayMessageAnimation(string imagePath) { DoubleAnimationUsingKeyFrames anim = new DoubleAnimationUsingKeyFrames(); DoubleAnimationUsingKeyFrames animBG = new DoubleAnimationUsingKeyFrames(); DoubleKeyFrameCollection kfCollection = new DoubleKeyFrameCollection(); DoubleKeyFrameCollection kfBGCollection = new DoubleKeyFrameCollection(); DoubleKeyFrame[] aFrames = new SplineDoubleKeyFrame[2] { new SplineDoubleKeyFrame(), new SplineDoubleKeyFrame() }; DoubleKeyFrame[] aBGFrames = new SplineDoubleKeyFrame[2] { new SplineDoubleKeyFrame(), new SplineDoubleKeyFrame() }; messageCanvas.IsHitTestVisible = true; m_bIgnoreAnimEnd = false; messageImage.Source = ResourceController.GetResourceBitmap(imagePath); aFrames[0].KeyTime = TimeSpan.FromSeconds(0.0); aFrames[0].Value = 0.0; aFrames[1].KeyTime = TimeSpan.FromSeconds(1.0); aFrames[1].Value = 1.0; /* aFrames[2].KeyTime = TimeSpan.FromSeconds(3.0); * aFrames[2].Value = 1.0; * aFrames[3].KeyTime = TimeSpan.FromSeconds(4.0); * aFrames[3].Value = 0.0;*/ aBGFrames[0].KeyTime = TimeSpan.FromSeconds(0.0); aBGFrames[0].Value = 1.0; aBGFrames[1].KeyTime = TimeSpan.FromSeconds(1.0); aBGFrames[1].Value = 0.0; /*aBGFrames[2].KeyTime = TimeSpan.FromSeconds(3.0); * aBGFrames[2].Value = 0.0; * aBGFrames[3].KeyTime = TimeSpan.FromSeconds(4.0); * aBGFrames[3].Value = 1.0;*/ for (int i = 0; i < aFrames.Length; i++) { kfCollection.Add(aFrames[i]); kfBGCollection.Add(aBGFrames[i]); } anim.KeyFrames = kfCollection; anim.Duration = TimeSpan.FromSeconds(1.0); anim.Completed += OnFirstMessageAnimationComplete; animBG.KeyFrames = kfBGCollection; animBG.Duration = TimeSpan.FromSeconds(1.0); animBG.Completed += OnFirstMessageAnimationComplete; messageCanvas.BeginAnimation(Canvas.OpacityProperty, anim); pageMainGrid.BeginAnimation(Grid.OpacityProperty, animBG); }
/// <summary> /// Warn user if they try to click on screenshot /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void onClick(object sender, EventArgs e) { var visKeyFrames = new ObjectKeyFrameCollection { new DiscreteObjectKeyFrame { KeyTime = TimeSpan.FromSeconds(0), Value = Visibility.Visible }, new DiscreteObjectKeyFrame { KeyTime = TimeSpan.FromSeconds(2.5), Value = Visibility.Collapsed } }; var opKeyFrames = new DoubleKeyFrameCollection { new DiscreteDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds(0), Value = 1 }, new LinearDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds(2), Value = 1 }, new LinearDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds(2.5), Value = 0 }, }; bdClick.BeginAnimation(TextBlock.VisibilityProperty, new ObjectAnimationUsingKeyFrames() { KeyFrames = visKeyFrames }); bdClick.BeginAnimation(TextBlock.OpacityProperty, new DoubleAnimationUsingKeyFrames() { KeyFrames = opKeyFrames }); }
/// <summary> /// Helper used by the four Freezable clone methods to copy the resolved key times and /// key frames. The Get*AsFrozenCore methods are implemented the same as the Clone*Core /// methods; Get*AsFrozen at the top level will recursively Freeze so it's not done here. /// </summary> /// <param name="sourceKeyFrameAnimation"></param> /// <param name="isCurrentValueClone"></param> private void CopyCommon(DoubleKeyFrameAnimation sourceKeyFrameAnimation, bool isCurrentValueClone) { _areKeyTimesValid = sourceKeyFrameAnimation._areKeyTimesValid; if (_areKeyTimesValid && sourceKeyFrameAnimation._sortedResolvedKeyFrames != null) { // _sortedResolvedKeyFrames is an array of ResolvedKeyFrameEntry so the notion of CurrentValueClone doesn't apply _sortedResolvedKeyFrames = (ResolvedKeyFrameEntry[])sourceKeyFrameAnimation._sortedResolvedKeyFrames.Clone(); } if (sourceKeyFrameAnimation._keyFrames == null) { return; } if (isCurrentValueClone) { _keyFrames = (DoubleKeyFrameCollection)sourceKeyFrameAnimation._keyFrames.CloneCurrentValue(); } else { _keyFrames = (DoubleKeyFrameCollection)sourceKeyFrameAnimation._keyFrames.Clone(); } OnFreezablePropertyChanged(null, _keyFrames); }
public void WrongAnimation() { const int nFlashCount = 3, nTotalCount = nFlashCount * 2; const double dFrameTime = 0.3; Image img = (Image)this.GetTemplateChild("ButtonAnimImage"); DoubleAnimationUsingKeyFrames anim = new DoubleAnimationUsingKeyFrames(); DoubleKeyFrameCollection kfCollection = new DoubleKeyFrameCollection(); EnableState(CmpButtonState.CBS_DISABLED); img.Source = m_WrongImage; img.Opacity = 0.0; double dCurTime = 0.0; for (int i = 0; i < nTotalCount; i++) { DoubleKeyFrame keyFrame = new DiscreteDoubleKeyFrame(); keyFrame.KeyTime = TimeSpan.FromSeconds(dCurTime); keyFrame.Value = (i % 2 == 0) ? 0.75 : 0; kfCollection.Add(keyFrame); dCurTime += (i == 0) ? 1.0 : dFrameTime; } anim.KeyFrames = kfCollection; anim.Duration = TimeSpan.FromSeconds(dCurTime); anim.Completed += OnWrongAnimationComplete; img.BeginAnimation(Image.OpacityProperty, anim); m_bIgnoreAnimEnd = false; }
private Storyboard Flash(ToggleButton target, EventHandler completed = null) { DoubleAnimationUsingKeyFrames easing = new DoubleAnimationUsingKeyFrames(); DoubleKeyFrameCollection dkfc = easing.KeyFrames; dkfc.Add(new EasingDoubleKeyFrame(0.2, TimeSpan.FromMilliseconds(300), new SineEase { EasingMode = EasingMode.EaseInOut })); dkfc.Add(new EasingDoubleKeyFrame(1.0, TimeSpan.FromMilliseconds(600), new SineEase { EasingMode = EasingMode.EaseInOut })); dkfc.Add(new EasingDoubleKeyFrame(0.2, TimeSpan.FromMilliseconds(900), new SineEase { EasingMode = EasingMode.EaseInOut })); dkfc.Add(new EasingDoubleKeyFrame(1.0, TimeSpan.FromMilliseconds(1200), new SineEase { EasingMode = EasingMode.EaseInOut })); Storyboard sb = new Storyboard(); if (completed != null) { sb.Completed += completed; } Storyboard.SetTarget(easing, target); Storyboard.SetTargetProperty(easing, new PropertyPath(ToggleButton.OpacityProperty)); sb.Children.Add(easing); sb.Begin(); return(sb); }
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(); }
private void PlayAnimation() { const int nFlashCount = 3, nTotalCount = nFlashCount * 2; const double dFrameTime = 0.3; DoubleAnimationUsingKeyFrames anim = new DoubleAnimationUsingKeyFrames(); DoubleKeyFrameCollection kfCollection = new DoubleKeyFrameCollection(); double dCurTime = 0.0; for (int i = 0; i < nTotalCount; i++) { DoubleKeyFrame keyFrame = new DiscreteDoubleKeyFrame(); keyFrame.KeyTime = TimeSpan.FromSeconds(dCurTime); keyFrame.Value = (i % 2 == 0) ? 0.75 : 0; kfCollection.Add(keyFrame); dCurTime += (i == 0 && !m_bValid) ? 1.0 : dFrameTime; } anim.KeyFrames = kfCollection; anim.Duration = TimeSpan.FromSeconds(dCurTime); anim.Completed += OnAnimationCompleted; m_animImg.BeginAnimation(Image.OpacityProperty, anim); m_bIgnoreAnimEnd = false; }
public void OnClick() { DoubleAnimationUsingKeyFrames anim = new DoubleAnimationUsingKeyFrames(); DoubleAnimationUsingKeyFrames animBG = new DoubleAnimationUsingKeyFrames(); DoubleKeyFrameCollection kfCollection = new DoubleKeyFrameCollection(); DoubleKeyFrameCollection kfBGCollection = new DoubleKeyFrameCollection(); DoubleKeyFrame[] aFrames = new SplineDoubleKeyFrame[2] { new SplineDoubleKeyFrame(), new SplineDoubleKeyFrame() }; DoubleKeyFrame[] aBGFrames = new SplineDoubleKeyFrame[2] { new SplineDoubleKeyFrame(), new SplineDoubleKeyFrame() }; MainWindow.last.HideClickableCanvas(); aFrames[0].KeyTime = TimeSpan.FromSeconds(0.0); aFrames[0].Value = 1.0; aFrames[1].KeyTime = TimeSpan.FromSeconds(1.0); aFrames[1].Value = 0.0; aBGFrames[0].KeyTime = TimeSpan.FromSeconds(0.0); aBGFrames[0].Value = 0.0; aBGFrames[1].KeyTime = TimeSpan.FromSeconds(1.0); aBGFrames[1].Value = 1.0; for (int i = 0; i < aFrames.Length; i++) { kfCollection.Add(aFrames[i]); kfBGCollection.Add(aBGFrames[i]); } anim.KeyFrames = kfCollection; anim.Duration = TimeSpan.FromSeconds(1.0); anim.Completed += OnSecondMessageAnimationComplete; animBG.KeyFrames = kfBGCollection; animBG.Duration = TimeSpan.FromSeconds(1.0); animBG.Completed += OnSecondMessageAnimationComplete; messageCanvas.BeginAnimation(Canvas.OpacityProperty, anim); pageMainGrid.BeginAnimation(Grid.OpacityProperty, animBG); }
private void ApplyContinuumElementAnimation() { this.continuumElementAnimation = new RadMoveAndFadeAnimation(); FrameworkElement rootVisual = Window.Current.Content as FrameworkElement; QuadraticEase easing = new QuadraticEase(); if (this.InOutAnimationMode == InOutAnimationMode.Out) { double durationInMs = 200; double keyTime = 0.2 * durationInMs; easing.EasingMode = EasingMode.EaseIn; this.continuumElementAnimation.MoveAnimation.StartPoint = new Point(0, 0); DoubleKeyFrameCollection middlePointsY = new DoubleKeyFrameCollection(); middlePointsY.Add(new EasingDoubleKeyFrame() { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(keyTime)), Value = 20 }); this.continuumElementAnimation.MoveAnimation.MiddlePointsYAxis = middlePointsY; DoubleKeyFrameCollection middlePointsX = new DoubleKeyFrameCollection(); middlePointsX.Add(new EasingDoubleKeyFrame() { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(keyTime)), Value = 10 }); this.continuumElementAnimation.MoveAnimation.MiddlePointsXAxis = middlePointsX; this.continuumElementAnimation.MoveAnimation.EndPoint = new Point(rootVisual.ActualWidth, this.continuumElement.ActualHeight); this.continuumElementAnimation.FadeAnimation.StartOpacity = 1; this.continuumElementAnimation.FadeAnimation.EndOpacity = 0; this.continuumElementAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(durationInMs)); } else { this.continuumElementAnimation.MoveAnimation.StartPoint = new Point((-1 * this.continuumElement.ActualWidth) - this.continuumElementScreenShotInfo.OriginalLocation.X, -2 * this.continuumElement.ActualHeight); this.continuumElementAnimation.MoveAnimation.EndPoint = new Point(0, 0); this.continuumElementAnimation.FadeAnimation.StartOpacity = 0; this.continuumElementAnimation.FadeAnimation.EndOpacity = 1; this.continuumElementAnimation.Duration = TimeSpan.FromMilliseconds(200); easing.EasingMode = EasingMode.EaseOut; } this.continuumElementAnimation.Easing = easing; this.continuumElementAnimation.Ended += this.ContinuumElementAnimation_Ended; }
private Storyboard Appear(UIElement target, EventHandler completed = null) { DoubleAnimationUsingKeyFrames easing = new DoubleAnimationUsingKeyFrames(); DoubleKeyFrameCollection dkfc = easing.KeyFrames; dkfc.Add(new EasingDoubleKeyFrame(1, TimeSpan.FromMilliseconds(300), new SineEase { EasingMode = EasingMode.EaseOut })); Storyboard sb = new Storyboard(); if (completed != null) { sb.Completed += completed; } Storyboard.SetTarget(easing, target); Storyboard.SetTargetProperty(easing, new PropertyPath(UIElement.OpacityProperty)); sb.Children.Add(easing); target.Opacity = 0; sb.Begin(); return(sb); }
/// <summary> /// Gets an array of interleaved duration/value pairs for this move animation's keyframes. /// </summary> /// <param name="startValue">The value of the first frame.</param> /// <param name="endValue">The value of the last frame.</param> /// <returns>Returns an array of interleaved duration/value pairs for this move animation's keyframes.</returns> protected double[] GetMoveArguments(double startValue, double endValue) { DoubleKeyFrameCollection middleValues = this.MiddlePointsAxis; double duration = this.Duration.TimeSpan.TotalSeconds; double[] result = new double[(this.MiddlePointsAxis.Count * 2) + 4]; // +4 for end and start arguments ... result[0] = 0; result[1] = startValue; for (int i = 0; i < middleValues.Count; i++) { int arrayIndex = 2 + (i * 2); result[arrayIndex] = middleValues[i].KeyTime.TimeSpan.TotalSeconds; result[arrayIndex + 1] = middleValues[i].Value; } result[(middleValues.Count * 2) + 2] = duration; result[(middleValues.Count * 2) + 3] = endValue; return(result); }
private void EventHandler(object sender, RoutedEventArgs e) { var diameter = 10; var length = panel.ActualWidth + diameter; var circlesCount = 6; var color = (Color)ColorConverter.ConvertFromString("#FF54ACE0"); var duration = TimeSpan.FromSeconds(5); panel.Children.Clear(); for (int i = 0; i < circlesCount; i++) { var transform = new TranslateTransform(-diameter, 0); var circle = new Ellipse() { Width = diameter, Height = diameter, Fill = new SolidColorBrush(color), RenderTransformOrigin = new Point(0.5, 0.5), RenderTransform = transform, }; panel.Children.Add(circle); var keyFrame = new SplineDoubleKeyFrame(length, KeyTime.FromPercent(0.5), new KeySpline(0, 0.95, 1, 0.05)); var keyFrames = new DoubleKeyFrameCollection(); keyFrames.Add(keyFrame); var animation = new DoubleAnimationUsingKeyFrames() { BeginTime = TimeSpan.FromMilliseconds(130 * i), Duration = duration, KeyFrames = keyFrames, RepeatBehavior = RepeatBehavior.Forever }; transform.BeginAnimation(TranslateTransform.XProperty, animation); } }