示例#1
0
        /// <summary>
        /// 1:This is my "play" button, this uses StoryBoard and Thickness animations so that once the button is pressed the  colorful bars move out of the way of the play area.
        /// 2:A Doubleanimation is used to "draw" the play area. It changes the opacity of the buttons from 0 to 1.
        /// 3: Once the buttons been pressed the "play" button becomes dissabled.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            #region The animations for the sticks are here

            //Animation for stick 1
            var sb = new Storyboard();
            var ta = new ThicknessAnimation();
            ta.BeginTime = new TimeSpan(0);
            ta.SetValue(Storyboard.TargetNameProperty, "stick1");
            Storyboard.SetTargetProperty(ta, new PropertyPath(MarginProperty));

            ta.From     = new Thickness(94, 0, 182, 0);
            ta.To       = new Thickness(94, 0, 500, 0);
            ta.Duration = new Duration(TimeSpan.FromSeconds(1));

            sb.Children.Add(ta);
            sb.Begin(this);

            //Stick2 animation
            ta.SetValue(Storyboard.TargetNameProperty, "stick2");
            Storyboard.SetTargetProperty(ta, new PropertyPath(MarginProperty));
            ta.From     = new Thickness(86, 0, -93, 0);
            ta.To       = new Thickness(86, 0, 500, 0);
            ta.Duration = new Duration(TimeSpan.FromSeconds(1));
            sb.Children.Add(ta);
            sb.Begin(this);

            //Stick3 animation
            ta.SetValue(Storyboard.TargetNameProperty, "stick3");
            Storyboard.SetTargetProperty(ta, new PropertyPath(MarginProperty));
            ta.From     = new Thickness(91, 0, 127, 0);
            ta.To       = new Thickness(91, 0, 500, 0);
            ta.Duration = new Duration(TimeSpan.FromSeconds(1));
            sb.Children.Add(ta);
            sb.Begin(this);

            //Stick4 animation
            ta.SetValue(Storyboard.TargetNameProperty, "stick4");
            Storyboard.SetTargetProperty(ta, new PropertyPath(MarginProperty));
            ta.From     = new Thickness(94, 0, 296, 0);
            ta.To       = new Thickness(94, 0, 500, 0);
            ta.Duration = new Duration(TimeSpan.FromSeconds(1));
            sb.Children.Add(ta);
            sb.Begin(this);

            //Stick5 animation
            ta.SetValue(Storyboard.TargetNameProperty, "stick5");
            Storyboard.SetTargetProperty(ta, new PropertyPath(MarginProperty));
            ta.From     = new Thickness(328, 0, -113, 0);
            ta.To       = new Thickness(328, 0, 500, 0);
            ta.Duration = new Duration(TimeSpan.FromSeconds(1));
            sb.Children.Add(ta);
            sb.Begin(this);

            //Stick6 animation
            ta.SetValue(Storyboard.TargetNameProperty, "stick6");
            Storyboard.SetTargetProperty(ta, new PropertyPath(MarginProperty));
            ta.From     = new Thickness(47, 0, 74, 0);
            ta.To       = new Thickness(47, 0, 500, 0);
            ta.Duration = new Duration(TimeSpan.FromSeconds(1));
            sb.Children.Add(ta);
            sb.Begin(this);

            //Stick7 animation
            ta.SetValue(Storyboard.TargetNameProperty, "stick7");
            Storyboard.SetTargetProperty(ta, new PropertyPath(MarginProperty));
            ta.From     = new Thickness(298, 0, 1, 0);
            ta.To       = new Thickness(298, 0, 500, 0);
            ta.Duration = new Duration(TimeSpan.FromSeconds(1));
            sb.Children.Add(ta);
            sb.Begin(this);


            //Stick8 animation
            ta.SetValue(Storyboard.TargetNameProperty, "stick8");
            Storyboard.SetTargetProperty(ta, new PropertyPath(MarginProperty));
            ta.From     = new Thickness(300, 0, -113, 0);
            ta.To       = new Thickness(300, 0, 500, 0);
            ta.Duration = new Duration(TimeSpan.FromSeconds(1));
            sb.Children.Add(ta);
            sb.Begin(this);

            //Stick 9
            ta.SetValue(Storyboard.TargetNameProperty, "stick9");
            Storyboard.SetTargetProperty(ta, new PropertyPath(MarginProperty));
            ta.From     = new Thickness(47, 0, -165, 0);
            ta.To       = new Thickness(47, 0, 500, 0);
            ta.Duration = new Duration(TimeSpan.FromSeconds(1));
            sb.Children.Add(ta);
            sb.Begin(this);

            #endregion


            #region Show the game area

            DoubleAnimation da = new DoubleAnimation();
            da.From     = 0;
            da.To       = 1;
            da.Duration = new Duration(TimeSpan.FromSeconds(2));

            Button0.BeginAnimation(OpacityProperty, da);
            Button1.BeginAnimation(OpacityProperty, da);
            Button2.BeginAnimation(OpacityProperty, da);
            Button3.BeginAnimation(OpacityProperty, da);
            Button4.BeginAnimation(OpacityProperty, da);
            Button5.BeginAnimation(OpacityProperty, da);
            Button6.BeginAnimation(OpacityProperty, da);
            Button7.BeginAnimation(OpacityProperty, da);
            Button8.BeginAnimation(OpacityProperty, da);

            #endregion

            #region disable the play button
            PlayButton.IsEnabled  = false;
            PlayButton.Background = Brushes.Gray;
            #endregion
        }