Beispiel #1
0
        private void ResetAnimation()
        {
            Timer?.Stop();
            Timer = null;

            TopBar.BeginAnimation(WidthProperty, null);
            BottomBar.BeginAnimation(WidthProperty, null);
            BottomBar.BeginAnimation(MarginProperty, null);

            BeforeText.BeginAnimation(OpacityProperty, null);
            AfterText.BeginAnimation(OpacityProperty, null);
            ChangeText.BeginAnimation(OpacityProperty, null);

            BeforeLine.BeginAnimation(OpacityProperty, null);
            BeforeLine.BeginAnimation(Line.X1Property, null);
            BeforeLine.BeginAnimation(Line.X2Property, null);
            AfterLine.BeginAnimation(OpacityProperty, null);
            AfterLine.BeginAnimation(Line.X1Property, null);
            AfterLine.BeginAnimation(Line.X2Property, null);
            AfterLine.BeginAnimation(Line.Y1Property, null);
        }
Beispiel #2
0
        public void Animate()
        {
            if (BeforeValue <= AfterValue)
            {
                TopBar.Fill = new SolidColorBrush(GetColor(BeforeValue));
                var BeforeValueAnimation = new DoubleAnimation()
                {
                    From           = 0,
                    To             = 300 * BeforeValue,
                    Duration       = TimeSpan.FromSeconds(0.5),
                    EasingFunction = new ExponentialEase()
                    {
                        EasingMode = EasingMode.EaseOut
                    }
                };
                BeforeValueAnimation.Completed += delegate
                {
                    BeforeText.Margin = new Thickness(300 * BeforeValue - BeforeText.ActualWidth / 2, 0, 0, 0);
                    BeforeText.BeginAnimation(OpacityProperty, new DoubleAnimation()
                    {
                        From           = 0,
                        To             = 1,
                        Duration       = TimeSpan.FromSeconds(0.5),
                        EasingFunction = new ExponentialEase()
                        {
                            EasingMode = EasingMode.EaseOut
                        }
                    });

                    Timer = new DispatcherTimer()
                    {
                        Interval = TimeSpan.FromSeconds(0.5)
                    };
                    Timer.Tick += delegate
                    {
                        StartChangeColor.Color = Color.FromArgb(0, 50, 205, 50);
                        EndChangeColor.Color   = Color.FromArgb(150, 50, 205, 50);
                        BottomBar.Margin       = new Thickness(300 * BeforeValue, 20, 0, 0);
                        var AfterValueAnimation = new DoubleAnimation()
                        {
                            From           = 0,
                            To             = 300 * (AfterValue - BeforeValue),
                            Duration       = TimeSpan.FromSeconds(0.5),
                            EasingFunction = new ExponentialEase()
                            {
                                EasingMode = EasingMode.EaseInOut
                            }
                        };
                        AfterValueAnimation.Completed += delegate
                        {
                            AfterText.Foreground = new SolidColorBrush(GetColor(AfterValue));
                            AfterText.BeginAnimation(OpacityProperty, new DoubleAnimation()
                            {
                                From           = 0,
                                To             = 1,
                                Duration       = TimeSpan.FromSeconds(0.5),
                                EasingFunction = new ExponentialEase()
                                {
                                    EasingMode = EasingMode.EaseOut
                                }
                            });

                            ChangeText.Foreground = Brushes.LimeGreen;
                            ChangeText.BeginAnimation(OpacityProperty, new DoubleAnimation()
                            {
                                From           = 0,
                                To             = 1,
                                Duration       = TimeSpan.FromSeconds(0.5),
                                EasingFunction = new ExponentialEase()
                                {
                                    EasingMode = EasingMode.EaseOut
                                }
                            });
                        };
                        BottomBar.BeginAnimation(WidthProperty, AfterValueAnimation);

                        //TopBar.Fill = TopBar.Fill.Clone();
                        //((SolidColorBrush)TopBar.Fill).BeginAnimation(SolidColorBrush.ColorProperty,
                        //    new ColorAnimation()
                        //    {
                        //        From = ((SolidColorBrush)TopBar.Fill).Color,
                        //        To = GetColor(AfterValue),
                        //        Duration = TimeSpan.FromSeconds(0.5),
                        //        EasingFunction = new ExponentialEase() { EasingMode = EasingMode.EaseInOut }
                        //    });

                        AfterLine.BeginAnimation(OpacityProperty, new DoubleAnimation()
                        {
                            From           = 0,
                            To             = 1,
                            Duration       = TimeSpan.FromSeconds(0.5),
                            EasingFunction = new ExponentialEase()
                            {
                                EasingMode = EasingMode.EaseInOut
                            }
                        });
                        AfterLine.BeginAnimation(Line.X1Property, new DoubleAnimation()
                        {
                            From           = 300 * BeforeValue,
                            To             = 300 * AfterValue,
                            Duration       = TimeSpan.FromSeconds(0.5),
                            EasingFunction = new ExponentialEase()
                            {
                                EasingMode = EasingMode.EaseInOut
                            }
                        });
                        AfterLine.BeginAnimation(Line.X2Property, new DoubleAnimation()
                        {
                            From           = 300 * BeforeValue,
                            To             = 300 * AfterValue,
                            Duration       = TimeSpan.FromSeconds(0.5),
                            EasingFunction = new ExponentialEase()
                            {
                                EasingMode = EasingMode.EaseInOut
                            }
                        });
                        if (BeforeText.Margin.Left + BeforeText.ActualWidth + 5 >=
                            300 * AfterValue - AfterText.ActualWidth / 2)
                        {
                            AfterText.Margin = new Thickness(300 * AfterValue -
                                                             AfterText.ActualWidth / 2, -10, 0, 0);
                            AfterLine.BeginAnimation(Line.Y1Property, new DoubleAnimation()
                            {
                                From           = 15,
                                To             = 5,
                                Duration       = TimeSpan.FromSeconds(0.5),
                                EasingFunction = new ExponentialEase()
                                {
                                    EasingMode = EasingMode.EaseInOut
                                }
                            });
                        }
                        else
                        {
                            AfterText.Margin = new Thickness(300 * AfterValue -
                                                             AfterText.ActualWidth / 2, 0, 0, 0);
                        }

                        Timer.Stop();
                    };
                    Timer.Start();
                };
                TopBar.BeginAnimation(WidthProperty, BeforeValueAnimation);
                BeforeLine.BeginAnimation(OpacityProperty, new DoubleAnimation()
                {
                    From           = 0,
                    To             = 1,
                    Duration       = TimeSpan.FromSeconds(0.5),
                    EasingFunction = new ExponentialEase()
                    {
                        EasingMode = EasingMode.EaseOut
                    }
                });
                BeforeLine.BeginAnimation(Line.X1Property, new DoubleAnimation()
                {
                    From           = 0,
                    To             = 300 * BeforeValue,
                    Duration       = TimeSpan.FromSeconds(0.5),
                    EasingFunction = new ExponentialEase()
                    {
                        EasingMode = EasingMode.EaseOut
                    }
                });
                BeforeLine.BeginAnimation(Line.X2Property, new DoubleAnimation()
                {
                    From           = 0,
                    To             = 300 * BeforeValue,
                    Duration       = TimeSpan.FromSeconds(0.5),
                    EasingFunction = new ExponentialEase()
                    {
                        EasingMode = EasingMode.EaseOut
                    }
                });
            }
            else
            {
                TopBar.Fill = new SolidColorBrush(GetColor(BeforeValue));
                var BeforeValueAnimation = new DoubleAnimation()
                {
                    From           = 0,
                    To             = 300 * BeforeValue,
                    Duration       = TimeSpan.FromSeconds(0.5),
                    EasingFunction = new ExponentialEase()
                    {
                        EasingMode = EasingMode.EaseOut
                    }
                };
                BeforeValueAnimation.Completed += delegate
                {
                    BeforeText.Margin = new Thickness(300 * BeforeValue - BeforeText.ActualWidth / 2, 0, 0, 0);
                    BeforeText.BeginAnimation(OpacityProperty, new DoubleAnimation()
                    {
                        From           = 0,
                        To             = 1,
                        Duration       = TimeSpan.FromSeconds(0.5),
                        EasingFunction = new ExponentialEase()
                        {
                            EasingMode = EasingMode.EaseOut
                        }
                    });

                    Timer = new DispatcherTimer()
                    {
                        Interval = TimeSpan.FromSeconds(0.5)
                    };
                    Timer.Tick += delegate
                    {
                        StartChangeColor.Color = Color.FromArgb(150, 255, 0, 0);
                        EndChangeColor.Color   = Color.FromArgb(0, 0, 0, 0);
                        var AfterValueAnimation = new ThicknessAnimation()
                        {
                            From           = new Thickness(300 * BeforeValue, 20, 0, 0),
                            To             = new Thickness(300 * AfterValue, 20, 0, 0),
                            Duration       = TimeSpan.FromSeconds(0.5),
                            EasingFunction = new ExponentialEase()
                            {
                                EasingMode = EasingMode.EaseInOut
                            }
                        };
                        AfterValueAnimation.Completed += delegate
                        {
                            AfterText.Foreground = new SolidColorBrush(GetColor(AfterValue));
                            AfterText.BeginAnimation(OpacityProperty, new DoubleAnimation()
                            {
                                From           = 0,
                                To             = 1,
                                Duration       = TimeSpan.FromSeconds(0.5),
                                EasingFunction = new ExponentialEase()
                                {
                                    EasingMode = EasingMode.EaseOut
                                }
                            });

                            ChangeText.Foreground = Brushes.Red;
                            ChangeText.BeginAnimation(OpacityProperty, new DoubleAnimation()
                            {
                                From           = 0,
                                To             = 1,
                                Duration       = TimeSpan.FromSeconds(0.5),
                                EasingFunction = new ExponentialEase()
                                {
                                    EasingMode = EasingMode.EaseOut
                                }
                            });
                        };
                        BottomBar.BeginAnimation(WidthProperty, new DoubleAnimation()
                        {
                            From           = 0,
                            To             = 300 * (BeforeValue - AfterValue),
                            Duration       = TimeSpan.FromSeconds(0.5),
                            EasingFunction = new ExponentialEase()
                            {
                                EasingMode = EasingMode.EaseInOut
                            }
                        });
                        BottomBar.BeginAnimation(MarginProperty, AfterValueAnimation);

                        TopBar.Fill = TopBar.Fill.Clone();
                        ((SolidColorBrush)TopBar.Fill).BeginAnimation(SolidColorBrush.ColorProperty,
                                                                      new ColorAnimation()
                        {
                            From           = ((SolidColorBrush)TopBar.Fill).Color,
                            To             = GetColor(AfterValue),
                            Duration       = TimeSpan.FromSeconds(0.5),
                            EasingFunction = new ExponentialEase()
                            {
                                EasingMode = EasingMode.EaseInOut
                            }
                        });
                        TopBar.BeginAnimation(WidthProperty, new DoubleAnimation()
                        {
                            From           = 300 * BeforeValue,
                            To             = 300 * AfterValue,
                            Duration       = TimeSpan.FromSeconds(0.5),
                            EasingFunction = new ExponentialEase()
                            {
                                EasingMode = EasingMode.EaseInOut
                            }
                        });

                        AfterLine.BeginAnimation(OpacityProperty, new DoubleAnimation()
                        {
                            From           = 0,
                            To             = 1,
                            Duration       = TimeSpan.FromSeconds(0.5),
                            EasingFunction = new ExponentialEase()
                            {
                                EasingMode = EasingMode.EaseInOut
                            }
                        });
                        AfterLine.BeginAnimation(Line.X1Property, new DoubleAnimation()
                        {
                            From           = 300 * BeforeValue,
                            To             = 300 * AfterValue,
                            Duration       = TimeSpan.FromSeconds(0.5),
                            EasingFunction = new ExponentialEase()
                            {
                                EasingMode = EasingMode.EaseInOut
                            }
                        });
                        AfterLine.BeginAnimation(Line.X2Property, new DoubleAnimation()
                        {
                            From           = 300 * BeforeValue,
                            To             = 300 * AfterValue,
                            Duration       = TimeSpan.FromSeconds(0.5),
                            EasingFunction = new ExponentialEase()
                            {
                                EasingMode = EasingMode.EaseInOut
                            }
                        });
                        if (BeforeText.Margin.Left - 5 <=
                            300 * AfterValue + AfterText.ActualWidth / 2)
                        {
                            AfterText.Margin = new Thickness(300 * AfterValue -
                                                             AfterText.ActualWidth / 2, -10, 0, 0);
                            AfterLine.BeginAnimation(Line.Y1Property, new DoubleAnimation()
                            {
                                From           = 15,
                                To             = 5,
                                Duration       = TimeSpan.FromSeconds(0.5),
                                EasingFunction = new ExponentialEase()
                                {
                                    EasingMode = EasingMode.EaseInOut
                                }
                            });
                        }
                        else
                        {
                            AfterText.Margin = new Thickness(300 * AfterValue -
                                                             AfterText.ActualWidth / 2, 0, 0, 0);
                        }

                        Timer.Stop();
                    };
                    Timer.Start();
                };
                TopBar.BeginAnimation(WidthProperty, BeforeValueAnimation);
                BeforeLine.BeginAnimation(OpacityProperty, new DoubleAnimation()
                {
                    From           = 0,
                    To             = 1,
                    Duration       = TimeSpan.FromSeconds(0.5),
                    EasingFunction = new ExponentialEase()
                    {
                        EasingMode = EasingMode.EaseOut
                    }
                });
                BeforeLine.BeginAnimation(Line.X1Property, new DoubleAnimation()
                {
                    From           = 0,
                    To             = 300 * BeforeValue,
                    Duration       = TimeSpan.FromSeconds(0.5),
                    EasingFunction = new ExponentialEase()
                    {
                        EasingMode = EasingMode.EaseOut
                    }
                });
                BeforeLine.BeginAnimation(Line.X2Property, new DoubleAnimation()
                {
                    From           = 0,
                    To             = 300 * BeforeValue,
                    Duration       = TimeSpan.FromSeconds(0.5),
                    EasingFunction = new ExponentialEase()
                    {
                        EasingMode = EasingMode.EaseOut
                    }
                });
            }
        }