/// <summary> /// /// </summary> /// <param name="index">index of child element on which to perform the animation.</param> private void PlayCompletePeelAnimation(string actionSender) { var index = GetPlayerPanelIndex(actionSender); if (index == -1) { return; } var animationTargetContainer = PlayerPanel.ItemContainerGenerator.ContainerFromIndex(index); var grid = VisualTreeHelper.GetChild(animationTargetContainer, 0); var ellipse = VisualTreeHelper.GetChild(grid, 0); var colorAnimation = new ColorAnimationUsingKeyFrames(); var frameA = new EasingColorKeyFrame(); frameA.KeyTime = TimeSpan.FromMilliseconds(200); frameA.Value = Colors.Green; frameA.EasingFunction = new QuadraticEase(); frameA.EasingFunction.EasingMode = EasingMode.EaseIn; var frameB = new EasingColorKeyFrame(); frameB.KeyTime = TimeSpan.FromMilliseconds(400); frameB.Value = Colors.Orange; frameB.EasingFunction = new QuadraticEase(); frameB.EasingFunction.EasingMode = EasingMode.EaseOut; colorAnimation.KeyFrames.Add(frameA); colorAnimation.KeyFrames.Add(frameB); Storyboard MyStoryBoard = new Storyboard(); Storyboard.SetTargetProperty(colorAnimation, "(Ellipse.Stroke).(SolidColorBrush.Color)"); Storyboard.SetTarget(colorAnimation, ellipse); MyStoryBoard.Children.Add(colorAnimation); MyStoryBoard.Begin(); PlayPeelAnimation(); }
// Animation code public void Letter_Animate(string controlName, int state) { Button targetButton = (Button)this.FindName(controlName); Color colText; if (state == 1) colText = colTextActive; else colText = colTextInactive; Color colBackground; if (state == 1) colBackground = colAccent; else colBackground = colPageBackground; // Animate Foreground Color LinearColorKeyFrame keyFrameCol = new LinearColorKeyFrame(); keyFrameCol.Value = colText; keyFrameCol.KeyTime = KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0, 2, 0)); ColorAnimationUsingKeyFrames animColor = new ColorAnimationUsingKeyFrames(); animColor.KeyFrames.Add(keyFrameCol); Storyboard.SetTargetProperty(animColor, "(TextElement.Foreground).(SolidColorBrush.Color)"); Storyboard.SetTarget(animColor, targetButton); // Animate Background Color LinearColorKeyFrame keyFrameColBG = new LinearColorKeyFrame(); keyFrameColBG.Value = colBackground; keyFrameColBG.KeyTime = KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0, 2, 0)); ColorAnimationUsingKeyFrames animColorBG = new ColorAnimationUsingKeyFrames(); animColorBG.KeyFrames.Add(keyFrameColBG); Storyboard.SetTargetProperty(animColorBG, "(Control.Background).(SolidColorBrush.Color)"); Storyboard.SetTarget(animColorBG, targetButton); // Play the Animation Storyboard story = new Storyboard(); story.Children.Add(animColor); story.Children.Add(animColorBG); story.Begin(); }