Beispiel #1
0
        public MainWindow()
        {
            InitializeComponent();

            AppForegroundColor = new SolidColorBrush((Color)FindResource("AppForegroundColor"));
            AppBackgroundColor = new SolidColorBrush((Color)FindResource("AppBackgroundColor"));
            CupWinColor        = new SolidColorBrush((Color)FindResource("CupWinColor"));
            CupWinDarkColor    = new SolidColorBrush((Color)FindResource("CupWinDarkColor"));
            CupLoseColor       = new SolidColorBrush((Color)FindResource("CupLoseColor"));
            CupLoseDarkColor   = new SolidColorBrush((Color)FindResource("CupLoseDarkColor"));
            CupDefaultColor    = new SolidColorBrush((Color)FindResource("CupDefaultColor"));

            rng  = new Random();
            cups = new Cup[]
            {
                new Cup(Cup1), new Cup(Cup2), new Cup(Cup3)
            };

            var marginProperty = DependencyProperty.Register("Margin", typeof(Thickness), typeof(Button));

            foreach (var cup in cups)
            {
                var animationFrames = new ThicknessKeyFrameCollection();
                animationFrames.Add(new SplineThicknessKeyFrame(new Thickness(32, 20, 32, 108), KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.2))));
                animationFrames.Add(new SplineThicknessKeyFrame(new Thickness(32, 20, 32, 108), KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1.8))));
                animationFrames.Add(new SplineThicknessKeyFrame(new Thickness(32, 64, 32, 64), KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2))));
                var animation = new ThicknessAnimationUsingKeyFrames();
                animation.KeyFrames = animationFrames;
                cup.Storyboard      = new Storyboard();
                cup.Storyboard.Children.Add(animation);
                Storyboard.SetTargetName(animation, cup.Button.Name);
                Storyboard.SetTargetProperty(animation, new PropertyPath(Button.MarginProperty));
            }

            gameTransition = false;
            streak         = 0;
            NewGame(false);
        }
        public static Storyboard AddSlideFromLeft(this Storyboard storyboard, IEnumerable <KeyFrame> keyFrameCollection, DependencyObject target = null, TimeSpan?beginTime = null)
        {
            var easingThicknessKeyFrames = keyFrameCollection.Select(frame =>
                                                                     new EasingThicknessKeyFrame(
                                                                         new Thickness(-frame.Offset, 0, frame.Offset, 0),
                                                                         KeyTime.FromTimeSpan(TimeSpan.FromSeconds(frame.Seconds)),
                                                                         frame.EasingFunction)
                                                                     );

            var keyFrames = new ThicknessKeyFrameCollection();

            foreach (var keyFrame in easingThicknessKeyFrames)
            {
                keyFrames.Add(keyFrame);
            }

            // Create the margin animate from right
            var animation = new ThicknessAnimationUsingKeyFrames
            {
                BeginTime = beginTime ?? new TimeSpan(0),
                KeyFrames = keyFrames
            };

            // Set the target property name
            Storyboard.SetTargetProperty(animation, new PropertyPath("Margin"));

            // Set the target if specified
            if (target != null)
            {
                Storyboard.SetTarget(animation, target);
            }

            // Add this to the storyboard
            storyboard.Children.Add(animation);

            return(storyboard);
        }