public static void NavigateTo <T> (this AnimatePage page, object parameter = null) where T : AnimatePage { ColorAnimationUsingKeyFrames ca = new ColorAnimationUsingKeyFrames( ); Storyboard.SetTargetName(ca, "BackgroundRect"); Storyboard.SetTargetProperty(ca, "(Shape.Fill).(SolidColorBrush.Color)"); ca.KeyFrames.Add(new EasingColorKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.25)), Value = AnimatePage.GetPageColor(page), EasingFunction = Uni.UI.XamlResources.Resources.EasingFunction }); ca.KeyFrames.Add(new EasingColorKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.5)), Value = AnimatePage.GetPageColor <T> ( ), EasingFunction = Uni.UI.XamlResources.Resources.EasingFunction }); page.GetLeaveStoryboard.Children.Add(ca); page.GetLeaveStoryboard.Completed += (obj, ev) => { page.Frame.Navigate(typeof(T), parameter, new BlankNavigationTransitionInfo( )); page.GetLeaveStoryboard.Stop( ); page.GetLeaveStoryboard.Children.Remove(ca); page.AddControl( ); }; page.RemoveControl( ); page.GetLeaveStoryboard.Begin( ); }
private void ColorAnimation(ListViewItem item) { var colorAnimation = new ColorAnimationUsingKeyFrames { BeginTime = TimeSpan.FromMilliseconds(300) }; var keyFrame1 = new LinearColorKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0)), Value = Colors.White }; var keyFrame2 = new LinearColorKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(400)), Value = Colors.Red }; var keyFrame3 = new LinearColorKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(1200)), Value = Colors.White }; colorAnimation.KeyFrames.Add(keyFrame1); colorAnimation.KeyFrames.Add(keyFrame2); colorAnimation.KeyFrames.Add(keyFrame3); Storyboard.SetTarget(colorAnimation, item); Storyboard.SetTargetProperty(colorAnimation, "(Control.Background).(SolidColorBrush.Color)"); var storyboard = new Storyboard(); storyboard.Children.Add(colorAnimation); storyboard.Begin(); }
private void OnListViewContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args) { if (args.ItemContainer != null && !args.InRecycleQueue && args.Phase == 0) { var colorAnimation = new ColorAnimationUsingKeyFrames { // 'cause the new item comes in with an animation of which duration is about 300s, we add a little delay here to only // animate the color after it appears. BeginTime = TimeSpan.FromMilliseconds(300) }; var keyFrame1 = new LinearColorKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0)), Value = Colors.White }; var keyFrame2 = new LinearColorKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(400)), Value = Colors.LightGray }; var keyFrame3 = new LinearColorKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(1200)), Value = Colors.White }; colorAnimation.KeyFrames.Add(keyFrame1); colorAnimation.KeyFrames.Add(keyFrame2); colorAnimation.KeyFrames.Add(keyFrame3); ListView.Background = new SolidColorBrush(Colors.Transparent); Storyboard.SetTarget(colorAnimation, args.ItemContainer); Storyboard.SetTargetProperty(colorAnimation, "(Control.Background).(SolidColorBrush.Color)"); var storyboard = new Storyboard(); storyboard.Children.Add(colorAnimation); storyboard.Begin(); } }
public static Timeline EaseAnimation(Color startColor) { // docs https://docs.microsoft.com/en-us/windows/uwp/graphics/key-frame-and-easing-function-animations#easing-functions var toRed = new EasingColorKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(500)), Value = Colors.Red, EasingFunction = new BounceEase { Bounces = 1, EasingMode = EasingMode.EaseIn } }; var back = new EasingColorKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(2000)), Value = startColor, EasingFunction = new SineEase { EasingMode = EasingMode.EaseIn } }; var colorAnimationUsingKeyFrames = new ColorAnimationUsingKeyFrames(); ColorKeyFrameCollection colorKeyFrameCollection = colorAnimationUsingKeyFrames.KeyFrames; colorKeyFrameCollection.Add(toRed); colorKeyFrameCollection.Add(back); return(colorAnimationUsingKeyFrames); }
// Token: 0x06000D03 RID: 3331 RVA: 0x00030818 File Offset: 0x0002EA18 private static Color?GetTargetColor(Timeline timeline, bool isEntering) { ColorAnimation colorAnimation = timeline as ColorAnimation; if (colorAnimation != null) { if (colorAnimation.From == null) { return(colorAnimation.To); } return(colorAnimation.From); } else { ColorAnimationUsingKeyFrames colorAnimationUsingKeyFrames = timeline as ColorAnimationUsingKeyFrames; if (colorAnimationUsingKeyFrames == null) { return(null); } if (colorAnimationUsingKeyFrames.KeyFrames.Count == 0) { return(null); } ColorKeyFrame colorKeyFrame = colorAnimationUsingKeyFrames.KeyFrames[isEntering ? 0 : (colorAnimationUsingKeyFrames.KeyFrames.Count - 1)]; return(new Color?(colorKeyFrame.Value)); } }
public static ColorAnimationUsingKeyFrames BlinkAnimation(Color startColor) { var toRed = new DiscreteColorKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(100)), Value = Colors.Red }; var keepRed = new DiscreteColorKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(500)), Value = Colors.Red }; var back = new LinearColorKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(1500)), Value = startColor }; var colorAnimationUsingKeyFrames = new ColorAnimationUsingKeyFrames(); ColorKeyFrameCollection colorKeyFrameCollection = colorAnimationUsingKeyFrames.KeyFrames; colorKeyFrameCollection.Add(toRed); colorKeyFrameCollection.Add(keepRed); colorKeyFrameCollection.Add(back); return(colorAnimationUsingKeyFrames); }
public static ColorAnimationUsingKeyFrames FreeAnimation(Color startColor) { // mutued from XAML example at https://docs.microsoft.com/en-us/uwp/api/Windows.UI.Xaml.Media.Animation.ColorAnimation var linearColorKeyFrame = new LinearColorKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(2000)), Value = Colors.Red }; var discreteColorKeyFrame = new DiscreteColorKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(2500)), Value = Colors.Yellow }; var splineColorKeyFrame = new SplineColorKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(4500)), Value = startColor, KeySpline = new KeySpline { ControlPoint1 = new Point(0.6, 0.0), ControlPoint2 = new Point(0.9, 0.0) } }; var colorAnimationUsingKeyFrames = new ColorAnimationUsingKeyFrames(); ColorKeyFrameCollection colorKeyFrameCollection = colorAnimationUsingKeyFrames.KeyFrames; colorKeyFrameCollection.Add(linearColorKeyFrame); colorKeyFrameCollection.Add(discreteColorKeyFrame); colorKeyFrameCollection.Add(splineColorKeyFrame); return(colorAnimationUsingKeyFrames); }
public void WriteMessage(string message, Color color) { SolidColorBrush colorBrush = new SolidColorBrush(color); validationField.Text = message; validationField.Foreground = colorBrush; //Выключаем сообщение через 10 сек ColorAnimationUsingKeyFrames colorAnimation = new ColorAnimationUsingKeyFrames(); colorAnimation.Duration = TimeSpan.FromSeconds(10); colorAnimation.KeyFrames.Add( new LinearColorKeyFrame( color, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(9.5))) ); colorAnimation.KeyFrames.Add( new LinearColorKeyFrame( Colors.Transparent, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(10))) ); colorBrush.BeginAnimation(SolidColorBrush.ColorProperty, colorAnimation); }
public ColorAnimation() { InitializeComponent(); DataContextChanged += (sender, args) => { if (args.NewValue is ColorAnimationViewModel implicitAnimationViewModel && _vm != implicitAnimationViewModel) { _vm = implicitAnimationViewModel; } }; _storyboard = new Storyboard(); var blinkColorBursh = (SolidColorBrush)TextBlockBlink.Foreground; ColorAnimationUsingKeyFrames blinkAnimation = ColorAnimationHelper.BlinkAnimation(blinkColorBursh.Color); AnimateTextBlockForeground(TextBlockBlink, blinkAnimation); var freeColorBrush = (SolidColorBrush)TextBlockFree.Foreground; ColorAnimationUsingKeyFrames freeAnimation = ColorAnimationHelper.FreeAnimation(freeColorBrush.Color); AnimateTextBlockForeground(TextBlockFree, freeAnimation); var easeColorBrush = (SolidColorBrush)TextBlockEase.Foreground; Timeline easeAnimation = ColorAnimationHelper.EaseAnimation(easeColorBrush.Color); AnimateTextBlockForeground(TextBlockEase, easeAnimation); _storyboard.Children.Add(blinkAnimation); _storyboard.Children.Add(freeAnimation); _storyboard.Children.Add(easeAnimation); }
public ListBox() { _colorAnimation = new ColorAnimation(); _colorAnimation.Name = "myColorAnimation"; _caukf = new ColorAnimationUsingKeyFrames(); _caukf.Name = "myCaukf"; }
private void Storyboard_Completed(object sender, EventArgs e) { Storyboard b = (Storyboard)this.Resources["FillStoryboard"]; ColorAnimationUsingKeyFrames cf = (ColorAnimationUsingKeyFrames)b.Children[1]; DoubleAnimationUsingKeyFrames df = (DoubleAnimationUsingKeyFrames)b.Children[0]; df.KeyFrames[0].Value = df.KeyFrames[1].Value; cf.KeyFrames[0].Value = cf.KeyFrames[1].Value; }
private void doRGB_click(object sender, RoutedEventArgs e) { NameScope.SetNameScope(this, new NameScope()); //SolidColorBrush animatedBrush = new SolidColorBrush(); btnDoRGB.Background = DoujinUtility.MainWindow.animatedBrush; btntest.Background = DoujinUtility.MainWindow.animatedBrush; DoujinUtility.MainWindow.animatedBrush.Color = Color.FromArgb(255, 255, 0, 0); this.RegisterName("AnimatedBrush", DoujinUtility.MainWindow.animatedBrush); ColorAnimationUsingKeyFrames colorAnimation = new ColorAnimationUsingKeyFrames(); colorAnimation.Duration = TimeSpan.FromSeconds(12); Color redColor = new Color(); redColor = Color.FromArgb(255, 255, 0, 0); Color greenColor = new Color(); greenColor = Color.FromArgb(255, 0, 255, 0); Color blueColor = new Color(); blueColor = Color.FromArgb(255, 0, 0, 255); colorAnimation.KeyFrames.Add( new LinearColorKeyFrame( greenColor, // Target value (KeyValue) KeyTime.FromTimeSpan(TimeSpan.FromSeconds(4.0))) // KeyTime ); colorAnimation.KeyFrames.Add( new LinearColorKeyFrame( blueColor, // Target value (KeyValue) KeyTime.FromTimeSpan(TimeSpan.FromSeconds(8.0))) // KeyTime ); colorAnimation.KeyFrames.Add( new LinearColorKeyFrame( redColor, // Target value (KeyValue) KeyTime.FromTimeSpan(TimeSpan.FromSeconds(12.0))) // KeyTime ); //colorAnimation.AutoReverse = true; colorAnimation.RepeatBehavior = RepeatBehavior.Forever; Storyboard.SetTargetName(colorAnimation, "AnimatedBrush"); Storyboard.SetTargetProperty(colorAnimation, new PropertyPath(SolidColorBrush.ColorProperty)); Storyboard myStoryboard = new Storyboard(); myStoryboard.Children.Add(colorAnimation); myStoryboard.Begin(this.btnDoRGB); /* btnDoRGB.Background = new SolidColorBrush(Colors.Red); * ColorAnimation animation2; * animation2 = new ColorAnimation(); * animation2.From = Color.FromArgb(100, 255, 0, 0); * animation2.To = Color.FromArgb(100, 0, 255, 255); * animation2.Duration = new Duration(TimeSpan.FromSeconds(1)); * animation2.AutoReverse = true; * animation2.RepeatBehavior = RepeatBehavior.Forever; * btnDoRGB.Background.BeginAnimation(SolidColorBrush.ColorProperty, animation2); */ }
public static ColorAnimationUsingKeyFrames AddKeyFrame(this ColorAnimationUsingKeyFrames objectAnimation, TimeSpan time, Color color) { objectAnimation.KeyFrames.Add(new EasingColorKeyFrame { KeyTime = KeyTime.FromTimeSpan(time), Value = color }); return(objectAnimation); }
static double _delay = 0.02; // 下一个门启动动画的延迟时间(秒) public void AnimateDoors() { double start = 0; Application.Current.Dispatcher.Invoke(new Action(() => { // 遍历 Grid 对象 foreach (Grid grid in this.canvas.Children) { if (grid == null) { continue; } foreach (Button button in grid.Children) { if (button == null) { continue; } var door = button.DataContext as DoorItem; if (door.State == "open") { continue; } var border = GetChildOfType <Border>(button); // https://docs.microsoft.com/en-us/dotnet/framework/wpf/graphics-multimedia/how-to-animate-color-by-using-key-frames ColorAnimationUsingKeyFrames colorAnimation = new ColorAnimationUsingKeyFrames(); colorAnimation.Duration = TimeSpan.FromSeconds(start + _length); // TODO: 应该从 <local:StateToBackConverter x:Key="StateToBack" OpenColor="DarkCyan" CloseColor="DarkGreen"/> 中去取 Color oldColor = Colors.DarkGreen; colorAnimation.KeyFrames.Add( new LinearColorKeyFrame( Colors.DarkOrange, // Target value (KeyValue) KeyTime.FromTimeSpan(TimeSpan.FromSeconds(start + _top))) // KeyTime ); colorAnimation.KeyFrames.Add( new LinearColorKeyFrame( oldColor, // Target value (KeyValue) KeyTime.FromTimeSpan(TimeSpan.FromSeconds(start + _length))) // KeyTime ); border.Background.BeginAnimation(SolidColorBrush.ColorProperty, colorAnimation); start += _delay; } } })); }
private void SetFrames(List <SplineColorKeyFrame> frames, string path, FrameworkElement element) { ColorAnimationUsingKeyFrames timeline = new ColorAnimationUsingKeyFrames(); Storyboard.SetTarget(timeline, element); Storyboard.SetTargetProperty(timeline, new PropertyPath(path, new object[0])); foreach (SplineColorKeyFrame frame in frames) { timeline.KeyFrames.Add(frame); } _storyboard.Children.Add(timeline); }
private static ColorAnimationUsingKeyFrames CreateColorAnimation(UIElement element, Duration duration, Color color) { var animation = new ColorAnimationUsingKeyFrames(); animation.KeyFrames.Add(new SplineColorKeyFrame() { KeyTime = duration.TimeSpan, Value = color }); Storyboard.SetTargetProperty(animation, new PropertyPath("(Shape.Fill).(SolidColorBrush.Color)")); Storyboard.SetTarget(animation, element); return(animation); }
public void setPrecent(double d) { if (showType == WaitAndProgressType.Waiting) { return; } Storyboard b = (Storyboard)this.Resources["FillStoryboard"]; DoubleAnimationUsingKeyFrames df = (DoubleAnimationUsingKeyFrames)b.Children[0]; ColorAnimationUsingKeyFrames cf = (ColorAnimationUsingKeyFrames)b.Children[1]; if (d >= 0 && d <= 10) { cf.KeyFrames[1].Value = ToColor("#FFFF3300"); } if (d > 10 && d <= 20) { cf.KeyFrames[1].Value = ToColor("#FFFF6600"); } if (d > 20 && d <= 30) { cf.KeyFrames[1].Value = ToColor("#FFFF9900"); } if (d > 30 && d <= 40) { cf.KeyFrames[1].Value = ToColor("#FFFFCC00"); } if (d > 40 && d <= 50) { cf.KeyFrames[1].Value = ToColor("#FFFFFF00"); } if (d > 50 && d <= 60) { cf.KeyFrames[1].Value = ToColor("#FFCCFF00"); } if (d > 60 && d <= 70) { cf.KeyFrames[1].Value = ToColor("#FF99FF00"); } if (d > 70 && d <= 80) { cf.KeyFrames[1].Value = ToColor("#FF66FF00"); } if (d > 80 && d <= 90) { cf.KeyFrames[1].Value = ToColor("#FF33FF00"); } if (d > 90 && d <= 100) { cf.KeyFrames[1].Value = ToColor("#FF00FF00"); } df.KeyFrames[1].Value = d * 3.6; b.Begin(); }
private static ColorAnimationUsingKeyFrames CreateVisibilityAnimation(DependencyObject element, Duration duration, Color color) { var animation = new ColorAnimationUsingKeyFrames(); animation.KeyFrames.Add(new SplineColorKeyFrame { KeyTime = new TimeSpan(duration.TimeSpan.Ticks), Value = color }); Storyboard.SetTargetProperty(animation, new PropertyPath("(Shape.Fill).(SolidColorBrush.Color)")); Storyboard.SetTarget(animation, element); return(animation); }
/// <summary> /// Starts the particle running or restarts the particle if it has expired /// </summary> /// <param name="rerun"></param> private void Run(bool rerun) { // only init the particle if it hasn't been run yet if (!rerun) { NameScope.SetNameScope(this, new NameScope()); this.Name = String.Format("p{0}", Particle.ParticleNo++); this.RegisterName(this.Name, this); this.Width = ParticleSystem.random.NextDouble(Owner.MinParticleWidth, Owner.MaxParticleWidth); this.Height = ParticleSystem.random.NextDouble(Owner.MinParticleHeight, Owner.MaxParticleHeight); this.particleSolidColorBrush = new SolidColorBrush(Colors.White); this.RegisterName(String.Format("{0}Brush", this.Name), particleSolidColorBrush); this.Background = particleSolidColorBrush; } // create the storyboard for this particle and hold its end behavior mStoryboard = new Storyboard(); mStoryboard.FillBehavior = FillBehavior.HoldEnd; // create a parallel timeline for the the opacity and background changes. ParallelTimeline pt = new ParallelTimeline(TimeSpan.FromSeconds(0)); // the timeline for the opacity change using the particle Start and End Opacity DoubleAnimation daOpacity = new DoubleAnimation(StartOpacity, EndOpacity, new Duration(TimeSpan.FromSeconds(this.LifeSpan))); Storyboard.SetTargetName(daOpacity, this.Name); Storyboard.SetTargetProperty(daOpacity, new PropertyPath(Particle.OpacityProperty)); // the timeline for the background color change using a colorkeyframecollection ColorAnimationUsingKeyFrames daBackground = new ColorAnimationUsingKeyFrames(); daBackground.Duration = new Duration(TimeSpan.FromSeconds(this.LifeSpan)); daBackground.KeyFrames = BackgroundColors; Storyboard.SetTargetName(daBackground, String.Format("{0}Brush", this.Name)); Storyboard.SetTargetProperty(daBackground, new PropertyPath(SolidColorBrush.ColorProperty)); pt.Children.Add(daOpacity); pt.Children.Add(daBackground); mStoryboard.Children.Add(pt); // the first time this is run begin the storyboard on load. if (!rerun) { this.Loaded += delegate(object sender, RoutedEventArgs args) { mStoryboard.Begin(this, true); }; } mIsAlive = true; }
// show which one is the winner when game is over, and show the mask rect to hide the game grids public void gameEndEffect(object sender, int winner) { this.Dispatcher.Invoke( new Action( delegate { // show the winner Label l = new Label(); l.Content = "WINNER!"; l.FontSize = WindowSizeGenerator.fontSizeLarge * 1.5; this.aCanvas.Children.Add(l); l.SetValue(Canvas.TopProperty, 0.25 * WindowSizeGenerator.screenHeight); if (winner == 0) { l.SetValue(Canvas.LeftProperty, 0.08 * WindowSizeGenerator.screenWidth); } else { l.SetValue(Canvas.LeftProperty, 0.70 * WindowSizeGenerator.screenWidth); } l.SetValue(Canvas.ZIndexProperty, 100); // begin to hide the game grids ColorAnimationUsingKeyFrames c1 = new ColorAnimationUsingKeyFrames(); double beginTime = 800; double timeDelay = 500; double timeStep = 000; c1.KeyFrames.Add(new LinearColorKeyFrame(Colors.Transparent, TimeSpan.FromMilliseconds(beginTime))); c1.KeyFrames.Add(new LinearColorKeyFrame(Colors.White, TimeSpan.FromMilliseconds(beginTime + timeDelay))); c1.KeyFrames.Add(new LinearColorKeyFrame(Colors.White, TimeSpan.FromMilliseconds(timeStep + beginTime + timeDelay)));; c1.Completed += gameEnd; aRect1.Fill.BeginAnimation(SolidColorBrush.ColorProperty, c1); ColorAnimationUsingKeyFrames c2 = new ColorAnimationUsingKeyFrames(); c2.KeyFrames.Add(new LinearColorKeyFrame(Colors.Transparent, TimeSpan.FromMilliseconds(beginTime))); c2.KeyFrames.Add(new LinearColorKeyFrame(Colors.White, TimeSpan.FromMilliseconds(beginTime + timeDelay))); c2.KeyFrames.Add(new LinearColorKeyFrame(Colors.White, TimeSpan.FromMilliseconds(timeStep + beginTime + timeDelay)));; c2.Completed += gameEnd; aRect2.Fill.BeginAnimation(SolidColorBrush.ColorProperty, c2); } ) ); }
public void ColorAnimationKeyFrameTest() { ColorAnimationUsingKeyFrames animation; animation = new ColorAnimationUsingKeyFrames(); animation.KeyFrames.Add(new DiscreteColorKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.2)), Value = Color.FromUInt32(20) }); animation.KeyFrames.Add(new DiscreteColorKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.2)), Value = Color.FromUInt32(40) }); animation.KeyFrames.Add(new DiscreteColorKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.8)), Value = Color.FromUInt32(60) }); ColorAnimationBasicTest(animation, Color.FromUInt32(50), Color.FromUInt32(150), Color.FromUInt32(50), Color.FromUInt32(40), Color.FromUInt32(60)); animation = new ColorAnimationUsingKeyFrames(); animation.KeyFrames.Add(new DiscreteColorKeyFrame { KeyTime = KeyTime.FromPercent(0.2), Value = Color.FromUInt32(40) }); animation.KeyFrames.Add(new DiscreteColorKeyFrame { KeyTime = KeyTime.FromPercent(0.8), Value = Color.FromUInt32(60) }); ColorAnimationBasicTest(animation, Color.FromUInt32(50), Color.FromUInt32(150), Color.FromUInt32(50), Color.FromUInt32(40), Color.FromUInt32(60)); animation = new ColorAnimationUsingKeyFrames(); animation.KeyFrames.Add(new LinearColorKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.2)), Value = Color.FromUInt32(40) }); animation.KeyFrames.Add(new LinearColorKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.8)), Value = Color.FromUInt32(60) }); ColorAnimationBasicTest(animation, Color.FromUInt32(50), Color.FromUInt32(150), Color.FromUInt32(50), Color.FromUInt32(50), Color.FromUInt32(60)); animation = new ColorAnimationUsingKeyFrames(); animation.KeyFrames.Add(new LinearColorKeyFrame { KeyTime = KeyTime.FromPercent(0.2), Value = Color.FromUInt32(20) }); animation.KeyFrames.Add(new LinearColorKeyFrame { KeyTime = KeyTime.FromPercent(0.2), Value = Color.FromUInt32(40) }); animation.KeyFrames.Add(new LinearColorKeyFrame { KeyTime = KeyTime.FromPercent(0.8), Value = Color.FromUInt32(60) }); ColorAnimationBasicTest(animation, Color.FromUInt32(50), Color.FromUInt32(150), Color.FromUInt32(50), Color.FromUInt32(50), Color.FromUInt32(60)); }
private void AddFadeInFadeOutKeyFrames(Storyboard sb, PhotoModel photo) { photo.Texture.Material.Color = Colors.Transparent; var keyFrames = new ColorAnimationUsingKeyFrames(); sb.Children.Add(keyFrames); keyFrames.KeyFrames.Add(new SplineColorKeyFrame(Colors.White, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(InTimeSpan)), AnimationKeySpline)); keyFrames.KeyFrames.Add(new LinearColorKeyFrame(Colors.White, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(OutTimeSpan - InTimeSpan)))); keyFrames.KeyFrames.Add(new SplineColorKeyFrame(Colors.Transparent, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(OutTimeSpan)), AnimationKeySpline)); Storyboard.SetTargetProperty(keyFrames, new PropertyPath("(GeometryModel3D.Material).(DiffuseMaterial.Color)")); Storyboard.SetTargetName(keyFrames, photo.ModelName); }
public override void CreateStoryboard() { ColorAnimationUsingKeyFrames dau = new ColorAnimationUsingKeyFrames(); EasingColorKeyFrame fromk = null; if (FromColor.HasValue) { fromk = new EasingColorKeyFrame(FromColor.Value, TimeSpan.FromMilliseconds(AniTime(0))); dau.KeyFrames.Add(fromk); } EasingColorKeyFrame tok = null; if (ToColor.HasValue) { tok = new EasingColorKeyFrame(ToColor.Value, TimeSpan.FromMilliseconds(AniTime(1))); dau.KeyFrames.Add(tok); } if (AniEasingFunction != null) { if (fromk != null) { fromk.EasingFunction = AniEasingFunction; } if (tok != null) { tok.EasingFunction = AniEasingFunction; } } else if (CirDefault != null) { if (fromk != null) { fromk.EasingFunction = CirDefault; } if (tok != null) { tok.EasingFunction = CirDefault; } } //Storyboard.SetTargetName(dau, ElementName); Storyboard.SetTarget(dau, Element); Storyboard.SetTargetProperty(dau, AniPropertyPath); Story.Children.Add(dau); }
private static void ScoreChanged(object sender, DependencyPropertyChangedEventArgs e) { var scoreLabel = (ScoreLabel)sender; if ((int)e.OldValue <= 0) // Beim ersten Wechsel Keine Animation abspielen. { scoreLabel.ActualScore = (int)e.NewValue; } else { Storyboard storyboard; if ((int)e.NewValue < (int)e.OldValue) { storyboard = (Storyboard)scoreLabel.Resources["ScoreDecreaseStoryBoard"]; } else if ((int)e.NewValue > (int)e.OldValue) { storyboard = (Storyboard)scoreLabel.Resources["ScoreIncreaseStoryBoard"]; } else { return; } foreach (var animation in storyboard.Children) { DoubleAnimation doubleAnimation = animation as DoubleAnimation; ColorAnimationUsingKeyFrames colorAnimation = animation as ColorAnimationUsingKeyFrames; if (doubleAnimation != null) { doubleAnimation.From = (int)e.OldValue; doubleAnimation.To = (int)e.NewValue; } if (colorAnimation != null) { foreach (ColorKeyFrame frame in colorAnimation.KeyFrames) { if (frame.Value == Colors.Black) { frame.Value = scoreLabel.ForegroundColor; } } } } //storyboard.SpeedRatio = 0.5; storyboard.Begin(); } }
public static ColorAnimationUsingKeyFrames AddDiscreteKeyFrame( this ColorAnimationUsingKeyFrames animation, double seconds, Color value) { var keyFrame = new DiscreteColorKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(seconds)), Value = value, }; animation.KeyFrames.Add(keyFrame); #if NETFX_CORE || WINDOWS_81_PORTABLE animation.EnableDependentAnimation = true; #endif return(animation); }
public void addColorAnimation(String control, Color value, int duration) { ColorAnimationUsingKeyFrames anim = new ColorAnimationUsingKeyFrames(); EasingColorKeyFrame eckf = new EasingColorKeyFrame(); eckf.Value = value; eckf.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(duration)); anim.BeginTime = TimeSpan.FromSeconds(beginTime); beginTime += duration; if (duration > 0) { animTimer.Add(beginTime); } Storyboard.SetTargetName(anim, control); Storyboard.SetTargetProperty(anim, new PropertyPath(SolidColorBrush.ColorProperty)); sb.Children.Add(anim); }
private void Window_Loaded(object sender, RoutedEventArgs e) { myPCamera.FarPlaneDistance = 20; myPCamera.NearPlaneDistance = 1; myPCamera.FieldOfView = 45; myPCamera.Position = new Point3D(-5, 2, 3); myPCamera.LookDirection = new Vector3D(5, -2, -3); myPCamera.UpDirection = new Vector3D(0, 1, 0); //Add light sources to the scene. myDirLight.Color = Colors.White; myDirLight.Direction = new Vector3D(-3, -4, -5); teapotModel.Geometry = (MeshGeometry3D)Application.Current.Resources["myTeapot"]; //Define material and apply to the mesh geometries. DiffuseMaterial teapotMaterial = new DiffuseMaterial(new SolidColorBrush(Colors.Tomato)); teapotModel.Material = teapotMaterial; RotateTransform3D myRotateTransform3D = new RotateTransform3D(); Quaternion q1 = new Quaternion(new Vector3D(0, 1, 0), 45); QuaternionRotation3D myQuaternionRotation3D1 = new QuaternionRotation3D(q1); myRotateTransform3D.Rotation = myQuaternionRotation3D1; teapotModel.Transform = myRotateTransform3D; QuaternionAnimation fst = new QuaternionAnimation(new Quaternion(new Vector3D(0, 1, 0), -180), new Quaternion(new Vector3D(0, 1, 0), 180), new Duration(TimeSpan.FromSeconds(1))); fst.RepeatBehavior = RepeatBehavior.Forever; fst.UseShortestPath = false; myRotateTransform3D.Rotation.BeginAnimation(QuaternionRotation3D.QuaternionProperty, fst); ColorAnimationUsingKeyFrames frameAnimation = new ColorAnimationUsingKeyFrames(); modelGroup.Children.Add(teapotModel); modelGroup.Children.Add(myDirLight); ModelVisual3D modelsVisual = new ModelVisual3D(); modelsVisual.Content = modelGroup; //Add the visual and camera to the Viewport3D. myViewport.Camera = myPCamera; myViewport.Children.Add(modelsVisual); this.Content = myViewport; }
/// <summary> /// 创建Color类型的关键帧动画 /// </summary> /// <param name="Model">动画数据</param> /// <returns></returns> public static ColorAnimationUsingKeyFrames BuildColorKeyFramesAnimation(ColorKeyFramesModel Model) { ColorAnimationUsingKeyFrames _colorAnimation = new ColorAnimationUsingKeyFrames(); _colorAnimation.Duration = (Model.Duration == 0? Duration.Automatic:new Duration(TimeSpan.FromSeconds(Model.Duration))); _colorAnimation.AutoReverse = Model.AutoReverse; _colorAnimation.BeginTime = TimeSpan.FromSeconds(Model.BeginTime); _colorAnimation.FillBehavior = Model.FillBehavior; _colorAnimation.RepeatBehavior = Model.RepeatBehavior; _colorAnimation.SpeedRatio = Model.SpeedRatio; foreach (var item in Model.KeyFrames) { _colorAnimation.KeyFrames.Add(CreateColorKeyFrmas(item)); } Storyboard.SetTarget(_colorAnimation, Model.Target); Storyboard.SetTargetProperty(_colorAnimation, new PropertyPath(Model.PropertyPath)); return(_colorAnimation); }
private void BeginColorAnimation(ref TextBlock txt, Color c0, Color c1, Color c2) { SolidColorBrush brushSC = new SolidColorBrush(); ColorAnimationUsingKeyFrames caKeyFrames = new ColorAnimationUsingKeyFrames(); ColorKeyFrameCollection keyFrames0 = caKeyFrames.KeyFrames; keyFrames0.Add(new LinearColorKeyFrame(c0, TimeSpan.FromSeconds(0))); keyFrames0.Add(new LinearColorKeyFrame(c1, TimeSpan.FromSeconds(2))); keyFrames0.Add(new LinearColorKeyFrame(c2, TimeSpan.FromSeconds(4))); keyFrames0.Add(new LinearColorKeyFrame(c0, TimeSpan.FromSeconds(6))); caKeyFrames.RepeatBehavior = RepeatBehavior.Forever; caKeyFrames.AutoReverse = true; brushSC.BeginAnimation(SolidColorBrush.ColorProperty, caKeyFrames, HandoffBehavior.Compose); txt.Foreground = brushSC; }
public HighlightField() { color = new SolidColorBrush(Colors.Transparent); ColorAnimationUsingKeyFrames animColor = new ColorAnimationUsingKeyFrames(); animColor.KeyFrames.Add(new LinearColorKeyFrame() { KeyTime = TimeSpan.FromSeconds(0.0), Value = Colors.Yellow }); animColor.KeyFrames.Add(new LinearColorKeyFrame() { KeyTime = time.TimeSpan, Value = Colors.Transparent }); animColor.Duration = time; story.Children.Add(animColor); Storyboard.SetTarget(animColor, this.color); Storyboard.SetTargetProperty(animColor, new PropertyPath("(Brush.Color)")); }