Ejemplo n.º 1
0
        public void ExecuteStoryboard()
        {
            try
            {
                StaticFunctions.AnimateScale(260, 178, 0, 0, this, 0.2);
                var fade = new DoubleAnimation
                {
                    From = 1,
                    To = 0,
                    Duration = TimeSpan.FromSeconds(0.3)
                };
                Storyboard.SetTarget(fade, this);
                Storyboard.SetTargetProperty(fade, new PropertyPath(UIElement.OpacityProperty));

                var sb = new Storyboard();
                sb.Children.Add(fade);
                sb.Begin();

                sb.Completed +=
                    (o, e1) =>
                    {
                        var parent = Parent as Grid;
                        parent.Children.Remove(this);
                    };
                sb.Begin();
            } catch { }
        }
        /// <summary>
        /// Default constructor.
        /// </summary>
        public SurfaceWindow1()
        {
            InitializeComponent();

            // Add handlers for window availability events
            AddWindowAvailabilityHandlers();

            flickr.DownloadStringCompleted += new DownloadStringCompletedEventHandler(flickr_DownloadStringCompleted);
            sb = this.FindResource("Animate") as Storyboard;

            if (settings.Load() == false)
            {
                tbError.Text = "Error loading Settings.";
                sb.Begin();
            }
            else
            {
                sFlickrAPIKey = settings.FlickrApiKey;
                if (sFlickrAPIKey == "")
                {
                    tbError.Text = "Flickr API Key not set.";
                    sb.Begin();
                }

                TagVisualizationDefinition1.Value = settings.ByteTag;
                if (TagVisualizationDefinition1.Value == "")
                {
                    tbError.Text = "No Byte Tag defined in Settings.";
                    sb.Begin();
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Animates specified property of the object.
        /// </summary>
        /// <param name="target">The target object to animate.</param>
        /// <param name="propertyPath">Property path, e.g. Canvas.Top.</param>
        /// <param name="from">Animation's starting value.</param>
        /// <param name="to">Animation's ending value.</param>
        /// <param name="milliseconds">Duration of the animation in milliseconds.</param>
        /// <param name="easingFunction">Easing function applied to the animation.</param>
        /// <param name="completed">Event handler called when animation completed.</param>
        /// <returns>Returns started storyboard.</returns>
        public static Storyboard AnimateDoubleProperty(this DependencyObject target, string propertyPath, double? from, double? to, double milliseconds,
            IEasingFunction easingFunction = null, EventHandler completed = null)
        {
            Duration duration = new Duration(TimeSpan.FromMilliseconds(milliseconds));
            DoubleAnimation doubleAnimation = new DoubleAnimation()
            {
                From = from,
                To = to,
                Duration = duration,
                EasingFunction = easingFunction
            };

            Storyboard storyboard = new Storyboard();
            storyboard.Duration = duration;
            storyboard.Children.Add(doubleAnimation);

            Storyboard.SetTarget(doubleAnimation, target);
            Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath(propertyPath));

            if (completed != null)
                storyboard.Completed += completed;

            storyboard.Begin();

            return storyboard;
        }
        void animating3_Completed(object sender, EventArgs e)
        {
            if(MainWindow.stopGesture)
            {
                myText.Content = "  2";
                var animation2Opacity = new DoubleAnimation();
                animation2Opacity.From = 1.0;
                animation2Opacity.To = 0;
                animation2Opacity.Duration = new Duration(TimeSpan.FromMilliseconds(1000));

                Storyboard.SetTarget(animation2Opacity, myText);
                Storyboard.SetTargetProperty(animation2Opacity, new PropertyPath(UIElement.OpacityProperty));

                Storyboard animating2 = new Storyboard();
                animating2.Children.Add(animation2Opacity);
                animating2.Completed += animating2_Completed;
                animating2.Begin();
            }
            else
            {
                myText.Visibility = Visibility.Collapsed;
                animationStarted = false;
            }

            

        }
Ejemplo n.º 5
0
 private void btnClose1_Click(object sender, RoutedEventArgs e)
 {
     if (std2 != null)
     {
         std2.Begin();
     }
 }
Ejemplo n.º 6
0
 public void Shake()
 {
     if (sb != null && sb.GetCurrentState() == ClockState.Active)
         return;
     sb = (Storyboard)Resources["shaking"];
     sb.Begin();
 }
Ejemplo n.º 7
0
		public PressureTank()
		{
			InitializeComponent();

			// Initialize visualization resources
			_pumpingStoryboard = (Storyboard)Resources["RotatePump"];
			_pumpingStoryboard.Begin();

			_pressureLevelStoryboard = (Storyboard)Resources["PressureLevel"];
			_pressureLevelStoryboard.Begin();
			_pressureLevelStoryboard.Pause();

			_timerAlertStoryboard = (Storyboard)Resources["TimerEvent"];
			_sensorAlertStoryboard = (Storyboard)Resources["SensorEvent"];

			// Initialize the simulation environment
			_simulator = new RealTimeSimulator(_model, stepDelay: 1000);
			_simulator.SimulationStateChanged += (o, e) => UpdateSimulationButtonVisibilities();
			_simulator.ModelStateChanged += (o, e) => UpdateModelState();

			// Initialize the visualization state
			UpdateSimulationButtonVisibilities();
			UpdateModelState();

			TimerAlert.Opacity = 0;
			SensorAlert.Opacity = 0;

			ChangeSpeed(8);
		}
Ejemplo n.º 8
0
        public PopupMsg(TextBlock msg)
        {
            //Store TextBlock for message display
            this.msg = msg;
            //Register the textblock's name, this is necessary for creating Storyboard using codes instead of XAML
            NameScope.SetNameScope(msg, new NameScope());
            msg.RegisterName("fadetext", msg);

            //Create the fade in & fade out animation
            DoubleAnimationUsingKeyFrames fadeInOutAni = new DoubleAnimationUsingKeyFrames();
            LinearDoubleKeyFrame keyframe = new LinearDoubleKeyFrame();
            keyframe.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2));
            keyframe.Value = 1;
            fadeInOutAni.KeyFrames.Add(keyframe);
            //keyframe = new LinearDoubleKeyFrame();

            fadeInOutAni.Duration = new Duration(TimeSpan.FromSeconds(4));        
            fadeInOutAni.AutoReverse = true;
            fadeInOutAni.AccelerationRatio = .2;
            fadeInOutAni.DecelerationRatio = .7;

            // Configure the animation to target the message's opacity property
            Storyboard.SetTargetName(fadeInOutAni, "fadetext");
            Storyboard.SetTargetProperty(fadeInOutAni, new PropertyPath(TextBlock.OpacityProperty));

            // Add the fade in & fade out animation to the Storyboard
            Storyboard fadeInOutStoryBoard = new Storyboard();
            fadeInOutStoryBoard.Children.Add(fadeInOutAni);

            // Set event trigger, make this animation played on an event we can control
            msg.IsVisibleChanged += delegate(object sender,  System.Windows.DependencyPropertyChangedEventArgs e)
            {
                if (msg.IsVisible) fadeInOutStoryBoard.Begin(msg);
            };
        }
Ejemplo n.º 9
0
        public void HideLoadingScreen()
        {
            new Thread(() =>
            {
                MainWindow.Grid_LoadingScreen.Dispatcher.BeginInvoke(
                    (Action)(() =>
                    {
                        // hide yellow background behind the taskbar icon
                        MainWindow.TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.None;

                        DoubleAnimation FadeOutAnimation = new DoubleAnimation();

                        FadeOutAnimation.From = 1;
                        FadeOutAnimation.To = 0;
                        FadeOutAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(FadeDuration));

                        Storyboard storyboard = new Storyboard();

                        storyboard.Children.Add(FadeOutAnimation);
                        Storyboard.SetTarget(FadeOutAnimation, MainWindow.Grid_LoadingScreen);
                        Storyboard.SetTargetProperty(FadeOutAnimation, new PropertyPath(Grid.OpacityProperty)); // Attached dependency property
                        storyboard.Begin();
                    }));

                Thread.Sleep(FadeDuration);

                MainWindow.Grid_LoadingScreen.Dispatcher.BeginInvoke(
                    (Action)(() =>
                    {
                        MainWindow.Grid_LoadingScreen.Visibility = Visibility.Hidden;
                    }));

            }).Start(); // start thread
        }
Ejemplo n.º 10
0
        public void appear()
        {
            sb = new Storyboard();
            da1 = new DoubleAnimation();
            da2 = new DoubleAnimation();
            absscisse.X1 = maincity.x_center + (maincity.r - 10) / 2;
            absscisse.X2 = maincity.x_center + (maincity.r - 10) / 2+1;
            absscisse.Y1 = maincity.y_center ;
               absscisse.Y2=  absscisse.Y1;
            ordinate.Y1 = maincity.y_center - maincity.r / 2;
               ordinate.X1 = maincity.x_center ;
              ordinate.X2 = maincity.x_center ;
              ordinate.Y2 = ordinate.Y1 + 1;
              // da1.From = maincity.x_center+(maincity.r-10)/2;
            //   da2.From = maincity.y_center-maincity.r/2;
             //  da1.To = c1.Width-maincity.x_center;
            //    da2.To = c1.Height - maincity.y_center;
               da1.To = 800;
            da2.To = 0;
            da1.Duration = TimeSpan.FromSeconds(1);
            da2.Duration = da1.Duration;

               Storyboard.SetTarget(da1, absscisse);
            Storyboard.SetTargetProperty(da1, new PropertyPath(Line.X2Property));
            Storyboard.SetTarget(da2, ordinate);
            Storyboard.SetTargetProperty(da2, new PropertyPath(Line.Y2Property));
            sb.Children.Add(da1);
               sb.Children.Add(da2);
               sb.Begin();
            //   maincity.textblock.Text += "lalallalalallalaaaaa";
              absscisse.Opacity = 1;
              ordinate.Opacity = 1;
        }
Ejemplo n.º 11
0
		public PressureTank()
		{
			InitializeComponent();

			// Initialize visualization resources
			_pumpingStoryboard = (Storyboard)Resources["RotatePump"];
			_pumpingStoryboard.Begin();

			_pressureLevelStoryboard = (Storyboard)Resources["PressureLevel"];
			_pressureLevelStoryboard.Begin();
			_pressureLevelStoryboard.Pause();

			_timerAlertStoryboard = (Storyboard)Resources["TimerEvent"];
			_sensorAlertStoryboard = (Storyboard)Resources["SensorEvent"];

			// Initialize the simulation environment
			SimulationControls.ModelStateChanged += (o, e) => UpdateModelState();
			SimulationControls.Reset += (o, e) => OnModelStateReset();
			SimulationControls.SetModel(new Model());

			// Initialize the visualization state
			UpdateModelState();

			TimerAlert.Opacity = 0;
			SensorAlert.Opacity = 0;
			SimulationControls.MaxSpeed = 64;
			SimulationControls.ChangeSpeed(8);
		}
        private static void OnTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var control = d as AnimatingTextControl;
            var newText = e.NewValue as string;

            var animation = new DoubleAnimation();
            animation.From = 1;
            animation.To = 0;
            animation.Duration = new Duration(TimeSpan.FromMilliseconds(200));

            animation.Completed += (sender, args) =>
                {
                    control.TheTextBlock.Text = newText;
                    var fadeInAnimation = new DoubleAnimation();
                    fadeInAnimation.From = 0.0;
                    fadeInAnimation.To = 1.0;
                    fadeInAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(200));

                    Storyboard.SetTarget(fadeInAnimation, control);
                    Storyboard.SetTargetProperty(fadeInAnimation, new PropertyPath("Opacity"));

                    var storyboard2 = new Storyboard();
                    storyboard2.Children.Add(fadeInAnimation);
                    storyboard2.Begin();
                };

            Storyboard.SetTarget(animation, control);
            Storyboard.SetTargetProperty(animation, new PropertyPath("Opacity"));

            var storyboard = new Storyboard();
            storyboard.Children.Add(animation);
            storyboard.Begin();
        }
Ejemplo n.º 13
0
        private void btn2_1_Click(object sender, RoutedEventArgs e)
        {
            RotateTransform animatedTranslateTransform = new RotateTransform();
              btn2_1.RenderTransform = animatedTranslateTransform;
              RegisterName("animateButton2", animatedTranslateTransform);

              DoubleAnimationUsingKeyFrames translationAnimation = new DoubleAnimationUsingKeyFrames();
              translationAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(0, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0))));

              EasingDoubleKeyFrame doubleKeyFrame2 = new EasingDoubleKeyFrame(360, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(10)));

              ElasticEase ease = new ElasticEase();
              ease.Oscillations = 3;
              ease.Springiness = 8;
              ease.EasingMode = EasingMode.EaseOut;

              doubleKeyFrame2.EasingFunction = ease;
              translationAnimation.KeyFrames.Add(doubleKeyFrame2);

              Storyboard.SetTargetName(translationAnimation, "animateButton2");
              Storyboard.SetTargetProperty(translationAnimation, new PropertyPath(RotateTransform.AngleProperty));

              Storyboard strbStoryboard = new Storyboard();
              strbStoryboard.Children.Add(translationAnimation);

              strbStoryboard.Begin(this);
              UnregisterName("animateButton2");
        }
Ejemplo n.º 14
0
        private void RunByCode(object sender, RoutedEventArgs e)
        {
            var storyBoard = new Storyboard();
            var animation1 = new DoubleAnimation
                {
                    To = 400, From = 0,
                    Duration = TimeSpan.FromSeconds(1),
                    FillBehavior = FillBehavior.HoldEnd
                };
            var animation2 = new DoubleAnimation
                {
                    To = 400, From = 0,
                    Duration = TimeSpan.FromSeconds(1),
                    FillBehavior = FillBehavior.HoldEnd
                };
            var animation3 = new DoubleAnimation
                {
                    To = 400, From = 0,
                    Duration = TimeSpan.FromSeconds(1),
                    FillBehavior = FillBehavior.HoldEnd
                };

            Storyboard.SetTargetName(animation1, "WhiteAthlete");
            Storyboard.SetTargetProperty(animation1, new PropertyPath(TranslateTransform.XProperty));
            Storyboard.SetTargetName(animation2, "BlackAthlete");
            Storyboard.SetTargetProperty(animation2, new PropertyPath(TranslateTransform.XProperty));
            Storyboard.SetTargetName(animation3, "BrownAthlete");
            Storyboard.SetTargetProperty(animation3, new PropertyPath(TranslateTransform.XProperty));

            storyBoard.Duration = TimeSpan.FromSeconds(1);
            storyBoard.Children.Add(animation1);
            storyBoard.Children.Add(animation2);
            storyBoard.Children.Add(animation3);
            storyBoard.Begin(this);
        }
Ejemplo n.º 15
0
        public override void PerformTranstition(UserControl newPage, UserControl oldPage)
        {
            this.newPage = newPage;
            this.oldPage = oldPage;

            Duration duration = new Duration(TimeSpan.FromSeconds(1));

            DoubleAnimation animation = new DoubleAnimation();
            animation.Duration = duration;
            switch (direction)
            {
                case WipeDirection.LeftToRight:
                    animation.To = oldPage.ActualWidth;
                    break;
                case WipeDirection.RightToLeft:
                    animation.To = -oldPage.ActualWidth;
                    break;
            }

            Storyboard sb = new Storyboard();
            sb.Duration = duration;
            sb.Children.Add(animation);
            sb.Completed += sb_Completed;

            TranslateTransform sc = new TranslateTransform();
            oldPage.RenderTransform = sc;

            Storyboard.SetTarget(animation, sc);
            Storyboard.SetTargetProperty(animation, new PropertyPath("X"));

            //oldPage.Resources.Add(sb);

            sb.Begin();
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 展开推文显示区域
        /// </summary>
        /// 
        /// <param name="mainWindow">主窗体this指针</param>
        /// <param name="expandHeight">需要展开的高度</param>
        public static void ExpandTweetPanel(MainWindow w,int expandHeight)
        {
            DoubleAnimation a = new DoubleAnimation();
            a.From = w.TweetPanel.Height;
            a.To = w.TweetPanel.Height + expandHeight;
            a.Duration = new Duration(TimeSpan.Parse("0:0:1"));
            a.AccelerationRatio = 0.5;
            a.DecelerationRatio = 0.5;
            Storyboard aHeightsb = new Storyboard();
            Storyboard.SetTargetProperty(a, new PropertyPath(StackPanel.HeightProperty));
            aHeightsb.Children.Add(a);
            aHeightsb.Begin(w.TweetPanel);

            DoubleAnimation b = new DoubleAnimation();
            b.From = w.Top;
            b.To = b.From - expandHeight;
            b.Duration = new Duration(TimeSpan.Parse("0:0:1"));
            b.AccelerationRatio = 0.5;
            b.DecelerationRatio = 0.5;
            w.BeginAnimation(Window.TopProperty, b);

            DoubleAnimation c = new DoubleAnimation();
            c.From = w.Height;
            c.To = w.Height + expandHeight;
            c.Duration = new Duration(TimeSpan.Parse("0:0:1"));
            c.AccelerationRatio = 0.5;
            c.DecelerationRatio = 0.5;
            w.BeginAnimation(MainWindow.HeightProperty, c);
        }
Ejemplo n.º 17
0
 /// <summary>
 /// 空间扭曲波动
 /// </summary>
 public void Wave(Point center)
 {
     DoubleAnimationUsingKeyFrames d0 = new DoubleAnimationUsingKeyFrames();
     SplineDoubleKeyFrame s0 = new SplineDoubleKeyFrame() { KeyTime = TimeSpan.Zero, Value = 70 };
     EasingDoubleKeyFrame e0 = new EasingDoubleKeyFrame() { EasingFunction = new SineEase() { EasingMode = EasingMode.EaseOut }, KeyTime = TimeSpan.FromMilliseconds(300), Value = 0 };
     d0.KeyFrames.Add(s0);
     d0.KeyFrames.Add(e0);
     Storyboard.SetTarget(d0, this);
     Storyboard.SetTargetProperty(d0, new PropertyPath("(UIElement.Effect).(RippleEffect.Frequency)"));
     DoubleAnimationUsingKeyFrames d1 = new DoubleAnimationUsingKeyFrames();
     SplineDoubleKeyFrame s1 = new SplineDoubleKeyFrame() { KeyTime = TimeSpan.Zero, Value = 0 };
     EasingDoubleKeyFrame e1 = new EasingDoubleKeyFrame() { KeyTime = TimeSpan.FromMilliseconds(150), Value = 0.01 };
     EasingDoubleKeyFrame e11 = new EasingDoubleKeyFrame() { EasingFunction = new SineEase() { EasingMode = EasingMode.EaseOut }, KeyTime = TimeSpan.FromMilliseconds(300), Value = 0 };
     d1.KeyFrames.Add(s1);
     d1.KeyFrames.Add(e1);
     d1.KeyFrames.Add(e11);
     Storyboard.SetTarget(d1, this);
     Storyboard.SetTargetProperty(d1, new PropertyPath("(UIElement.Effect).(RippleEffect.Amplitude)"));
     if (waveStoryboard != null) { Wave_Completed(waveStoryboard, null); }
     center.X = (center.X + offset.X) / mapRoot.BodyWidth;
     center.Y = (center.Y + offset.Y) / mapRoot.BodyHeight;
     this.Effect = new WaveRipple() { Phase = 0, Amplitude = 0, Frequency = 0, Center = center };
     waveStoryboard = new Storyboard();
     waveStoryboard.Children.Add(d0);
     waveStoryboard.Children.Add(d1);
     waveStoryboard.Completed += new EventHandler(Wave_Completed);
     waveStoryboard.Begin();
 }
Ejemplo n.º 18
0
 public StepFiveControl(MainWindow window)
 {
     InitializeComponent();
     countdownControl.Initial(200, 170, 200,60);
     countdownControl.CountdownCompleted += () => {
         countdownControl.Visibility = Visibility.Collapsed;
         PlaySound();
     };
     sb = Resources["sb1"] as Storyboard;
     media.MediaEnded += OnSceneOver;
     media.MediaFailed += (sender, args) =>
     {
         _isMediaPlaying = false;
     };
     media.MediaOpened += (s, e) =>
     {
         //Panel.SetZIndex(media, 999);
         //border.Visibility = Visibility.Collapsed;
         //media.Opacity = 1;
         sb.Begin(media, true);
     };
     sb.Completed += (s, e) =>
     {
         sb.Remove(media);
         media.Opacity = 1;
     };
     Window = window;
 }
Ejemplo n.º 19
0
 private static void ImageQueue_OnComplate(Image i, string u, BitmapImage b)
 {
     //System.Windows.MessageBox.Show(u);
     string source = ImageDecoder.GetSource(i);
     if (source == u.ToString())
     {
         i.Source = b;
         Storyboard storyboard = new Storyboard();
         DoubleAnimation doubleAnimation = new DoubleAnimation(0.0, 1.0, new Duration(TimeSpan.FromMilliseconds(500.0)));
         Storyboard.SetTarget(doubleAnimation, i);
         Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("Opacity", new object[0]));
         storyboard.Children.Add(doubleAnimation);
         storyboard.Begin();
         if (i.Parent is Grid)
         {
             Grid grid = i.Parent as Grid;
             //foreach (var c in grid.Children)
             //{
             //    if (c is WaitingProgress && c != null)
             //    {
             //        (c as WaitingProgress).Stop();
             //        break;
             //    }
             //}
         }
     }
 }
Ejemplo n.º 20
0
        private void FadeIn()
        {
            if (_Running)
            {
                DoubleAnimation fadeIn = new DoubleAnimation();

                fadeIn.From = 0.0;
                fadeIn.To = 1;
                fadeIn.Duration = new Duration(TimeSpan.FromSeconds(2));
                fadeIn.BeginTime = TimeSpan.FromSeconds(2);

                Storyboard sb = new Storyboard();

                Storyboard.SetTarget(fadeIn, _Control);
                Storyboard.SetTargetProperty(fadeIn, new PropertyPath("(Opacity)"));

                sb.Children.Add(fadeIn);

                _Control.Resources.Clear();
                _Control.Resources.Add("FaderEffect", sb);

                sb.Completed += this.OnFadeInCompleted;

                sb.Begin();
            }
        }
Ejemplo n.º 21
0
        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            OuterGrid.Effect = new SlideInTransitionEffect
            {
                // To comment out the codes below, the first line text in the blue block will not shake while tansiting.
                // This snapped bitmap is little blurry, that means the RenderTargetBitmap renders in a different way.
                // How can I get a the same screenshot as the control?
                Input = new ImageBrush(TakeImage(InnerGrid))
            };

            var animation = new DoubleAnimation(0.0, 1.0, new Duration(TimeSpan.FromSeconds(0.8)))
            {
                AccelerationRatio = 0.5,
                DecelerationRatio = 0.5
            };

            Storyboard.SetTarget(animation, OuterGrid);
            Storyboard.SetTargetProperty(animation, new PropertyPath("Effect.Progress"));

            var storyboard = new Storyboard();
            storyboard.Completed += Storyboard_Completed;

            storyboard.Children.Add(animation);
            storyboard.Begin();
        }
Ejemplo n.º 22
0
        private void PerformCaptureAnimation()
        {
            LoadingView.Text = "Processing ...";
            ShowLoadingView();

            curtain = new Rectangle();
            curtain.Fill = new SolidColorBrush(Colors.White);
            LayoutRoot.Children.Add(curtain);

            Storyboard animation = new Storyboard();
            Duration duration = new Duration(TimeSpan.FromSeconds(0.3));
            animation.Duration = duration;

            DoubleAnimation curtainAnimation = new DoubleAnimation();
            animation.Children.Add(curtainAnimation);
            curtainAnimation.Duration = duration;
            curtainAnimation.To = 0;
            curtainAnimation.EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseIn };
            Storyboard.SetTarget(curtainAnimation, curtain);
            Storyboard.SetTargetProperty(curtainAnimation, new PropertyPath("Opacity"));

            animation.Completed += (sender, e) => {
                LayoutRoot.Children.Remove(curtain);
            };

            animation.Begin();
        }
Ejemplo n.º 23
0
        private static void StartTimeline(Timeline timeline)
        {
            timeline.Completed += Timeline_Completed;
            timeline.Begin();

            _actives.SetAnimationState(GetTimelineGuid(timeline), AnimationState.Running);
        }
Ejemplo n.º 24
0
        public static void AnimateScrollIntoViewMainMenu(this ItemsControl itemsControl, object item)
        {
            try
            {
                ScrollViewer scrollViewer = VisualTreeHelpers.GetVisualChild<ScrollViewer>(itemsControl);

                UIElement container = itemsControl.ItemContainerGenerator.ContainerFromItem(item) as UIElement;
                int index = itemsControl.ItemContainerGenerator.IndexFromContainer(container);
                double toValue = scrollViewer.ExtentWidth * ((double)index / itemsControl.Items.Count);
                Point relativePoint = container.TranslatePoint(new Point(0.0, 0.0), Window.GetWindow(container));

                DoubleAnimation horizontalAnimation = new DoubleAnimation();
                horizontalAnimation.From = scrollViewer.HorizontalOffset;
                horizontalAnimation.To = toValue;
                horizontalAnimation.DecelerationRatio = .2;
                horizontalAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(1000));
                Storyboard storyboard = new Storyboard();
                storyboard.Children.Add(horizontalAnimation);
                Storyboard.SetTarget(horizontalAnimation, scrollViewer);
                Storyboard.SetTargetProperty(horizontalAnimation, new PropertyPath(ScrollViewerBehavior.HorizontalOffsetProperty));
                storyboard.Begin();
            }
            catch (Exception)
            {

                
            }
        }
        public void ForeverBlinkerLoaded(object sender, RoutedEventArgs e)
        {
            FrameworkElement fe = sender as FrameworkElement;

            if (fe != null)
            {
                System.Windows.Media.Animation.QuadraticEase QEaseOut = new System.Windows.Media.Animation.QuadraticEase()
                {
                    EasingMode = System.Windows.Media.Animation.EasingMode.EaseOut
                };
                System.Windows.Media.Animation.Storyboard SB = new System.Windows.Media.Animation.Storyboard();
                SB.RepeatBehavior = RepeatBehavior.Forever;
                SB.Duration       = System.TimeSpan.FromMilliseconds(500 * SpeedRatio);

                System.Windows.Media.Animation.DoubleAnimation fadeout = new System.Windows.Media.Animation.DoubleAnimation(0, System.TimeSpan.FromMilliseconds(100 * SpeedRatio));
                fadeout.BeginTime      = new System.TimeSpan(0, 0, 0, 0, 0);
                fadeout.EasingFunction = QEaseOut;
                System.Windows.Media.Animation.Storyboard.SetTarget(fadeout, fe);
                System.Windows.Media.Animation.Storyboard.SetTargetProperty(fadeout, new PropertyPath(TextBlock.OpacityProperty));
                SB.Children.Add(fadeout);

                System.Windows.Media.Animation.DoubleAnimation fadein = new System.Windows.Media.Animation.DoubleAnimation(1, System.TimeSpan.FromMilliseconds(100 * SpeedRatio));
                fadein.BeginTime      = new System.TimeSpan(0, 0, 0, 0, 200);
                fadein.EasingFunction = QEaseOut;
                System.Windows.Media.Animation.Storyboard.SetTarget(fadein, fe);
                System.Windows.Media.Animation.Storyboard.SetTargetProperty(fadein, new PropertyPath(TextBlock.OpacityProperty));
                SB.Children.Add(fadein);

                SB.Begin();
            }
        }
        public static Task SmoothSetAsync(this FrameworkElement @this, DependencyProperty dp, double targetvalue,
            TimeSpan iDuration, CancellationToken iCancellationToken)
        {
            TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
            DoubleAnimation anim = new DoubleAnimation(targetvalue, new Duration(iDuration));
            PropertyPath p = new PropertyPath("(0)", dp);
            Storyboard.SetTargetProperty(anim, p);
            Storyboard sb = new Storyboard();
            sb.Children.Add(anim);
            EventHandler handler = null;
            handler = delegate
            {
                sb.Completed -= handler;
                sb.Remove(@this);
                @this.SetValue(dp, targetvalue);
                tcs.TrySetResult(null);
            };
            sb.Completed += handler;
            sb.Begin(@this, true);

            iCancellationToken.Register(() =>
            {
                double v = (double)@this.GetValue(dp);  
                sb.Stop(); 
                sb.Remove(@this); 
                @this.SetValue(dp, v);
                tcs.TrySetCanceled();
            });

            return tcs.Task;
        }
        private static void TypewriteTextblock(string textToAnimate, TextBlock txt, TimeSpan timeSpan)
        {
            var story = new Storyboard
            {
                FillBehavior = FillBehavior.HoldEnd
            };

            DiscreteStringKeyFrame discreteStringKeyFrame;
            var stringAnimationUsingKeyFrames = new StringAnimationUsingKeyFrames
            {
                Duration = new Duration(timeSpan)
            };

            var tmp = string.Empty;
            foreach (var c in textToAnimate)
            {
                discreteStringKeyFrame = new DiscreteStringKeyFrame
                {
                    KeyTime = KeyTime.Paced
                };
                tmp += c;
                discreteStringKeyFrame.Value = tmp;
                stringAnimationUsingKeyFrames.KeyFrames.Add(discreteStringKeyFrame);
            }

            Storyboard.SetTargetName(stringAnimationUsingKeyFrames, txt.Name);
            Storyboard.SetTargetProperty(stringAnimationUsingKeyFrames, new PropertyPath(TextBlock.TextProperty));
            story.Children.Add(stringAnimationUsingKeyFrames);
            story.Begin(txt);
        }
Ejemplo n.º 28
0
 /// <summary>
 /// Creates a Storyboard with this Timeline, sets the target and target property
 /// accordingly, and begins the animation.
 /// </summary>
 /// <param name="animation">The Timeline that will be started.</param>
 /// <param name="target">The actual instance of the object to target.</param>
 /// <param name="propertyPath">A dependency property identifier or property path string that describes the
 /// property that will be animated.</param>
 public static void BeginAnimation(this Timeline animation, DependencyObject target, object propertyPath)
 {
     animation.SetTargetAndProperty(target, propertyPath);
     var sb = new Storyboard();
     sb.Children.Add(animation);
     sb.Begin();
 }
Ejemplo n.º 29
0
 public static void SetScrollEffect(DependencyObject obj, int value)
 {
     var elem = obj as FrameworkElement;
     var transGroup = new TransformGroup();
     transGroup.Children.Add(new ScaleTransform());
     transGroup.Children.Add(new SkewTransform());
     transGroup.Children.Add(new RotateTransform());
     transGroup.Children.Add(new TranslateTransform());
     elem.RenderTransform = transGroup;
     var sb = new Storyboard();
     var da = new DoubleAnimationUsingKeyFrames();
     Storyboard.SetTarget(da, obj);
     Storyboard.SetTargetProperty(da, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)", new object[0]));
     da.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.Zero), Value = 60 });
     da.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(value)), Value = 60 });
     da.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(value + 900)), Value = 0, EasingFunction = new CircleEase { EasingMode = EasingMode.EaseOut } });
     sb.Children.Add(da);
     var da2 = new DoubleAnimationUsingKeyFrames();
     Storyboard.SetTarget(da2, obj);
     Storyboard.SetTargetProperty(da2, new PropertyPath(UIElement.OpacityProperty));
     da2.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.Zero), Value = 0 });
     da2.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(value)), Value = 0 });
     da2.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(value + 400)), Value = 1 });
     sb.Children.Add(da2);
     elem.Loaded += (a, b) =>
     {
         sb.Begin();
     };
     obj.SetValue(ScrollEffectProperty, value);
 }
        private void PerformAppearanceAnimation()
        {
            double w = System.Windows.Application.Current.Host.Content.ActualWidth;
            double h = System.Windows.Application.Current.Host.Content.ActualHeight;

            CompositeTransform ct = (CompositeTransform)LayoutRoot.RenderTransform;
            ct.TranslateY = h;

            LayoutRoot.Visibility = Visibility.Visible;

            Storyboard animation = new Storyboard();
            animation.Duration = new Duration(TimeSpan.FromSeconds(0.3));

            // Y animation
            DoubleAnimation galleryAnimation = new DoubleAnimation();
            galleryAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.3));
            galleryAnimation.To = 0.0;
            galleryAnimation.EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseOut };
            Storyboard.SetTarget(galleryAnimation, LayoutRoot);
            Storyboard.SetTargetProperty(galleryAnimation, new PropertyPath("(UIElement.RenderTransform).(CompositeTransform.TranslateY)"));
            animation.Children.Add(galleryAnimation);
            animation.Begin();
            animation.Completed += (sender, e) =>
            {
                OnPageAppeared();
            };
        }
Ejemplo n.º 31
0
        public void DismissEVHUD()
        {
            if (evHUDView == null)
            {
                return;
            }

            Storyboard storyboard = new Storyboard();
            Duration duration = new Duration(TimeSpan.FromSeconds(0.3));
            storyboard.Duration = duration;

            DoubleAnimation panelAnimation = new DoubleAnimation();
            panelAnimation.Duration = duration;
            panelAnimation.To = evHUDView.Width;
            panelAnimation.EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseOut };
            Storyboard.SetTarget(panelAnimation, evHUDView);
            Storyboard.SetTargetProperty(panelAnimation, new PropertyPath("(UIElement.RenderTransform).(TranslateTransform.X)"));
            storyboard.Children.Add(panelAnimation);

            storyboard.Begin();
            storyboard.Completed += (sender, e) =>
            {
                evHUDView.Visibility = Visibility.Collapsed;

                if (Orientation == PageOrientation.LandscapeLeft || Orientation == PageOrientation.LandscapeRight)
                {
                    ShowLandscapeShutterButton();
                }

            };
        }
Ejemplo n.º 32
0
        public override void Run(
            IAnimationContext context,
            Control control,
            TimeSpan duration,
            Action<Control> endMethod)
        {
            var storyboard = new Storyboard();

            DoubleAnimation fadeAnimation;

            if ( rounds > 1 )
            {
                fadeAnimation = new DoubleAnimation( startOpacity, endOpacity, new Duration( duration ) );
                fadeAnimation.AutoReverse = true;
                fadeAnimation.RepeatBehavior = new RepeatBehavior( rounds - 1 );
                storyboard.Children.Add( fadeAnimation );
                Storyboard.SetTarget( fadeAnimation, control );
                Storyboard.SetTargetProperty( fadeAnimation, new PropertyPath( UIElement.OpacityProperty ) );
            }

            fadeAnimation = new DoubleAnimation( startOpacity, endOpacity, new Duration( duration ) );
            fadeAnimation.BeginTime = TimeSpan.FromMilliseconds( duration.TotalMilliseconds * ( rounds - 1 ) * 2 );
            storyboard.Children.Add( fadeAnimation );
            Storyboard.SetTarget( fadeAnimation, control );
            Storyboard.SetTargetProperty( fadeAnimation, new PropertyPath( UIElement.OpacityProperty ) );

            if ( endMethod != null )
                storyboard.Completed += ( s, a ) => endMethod( control );
            storyboard.Begin( control );
        }
Ejemplo n.º 33
0
 private void btnClose_Click(object sender, RoutedEventArgs e)
 {
     if (std != null)
     {
         std.Begin();
     }
     //Application.Current.Shutdown();
 }
Ejemplo n.º 34
0
        /// <summary>
        /// 开始登录动画
        /// </summary>
        private void BeginLoginStd()
        {
            DoubleAnimation da = new DoubleAnimation();

            da.Duration = new Duration(TimeSpan.FromSeconds(1));
            da.To       = -180d;
            this.axr.BeginAnimation(AxisAngleRotation3D.AngleProperty, da);
            storyboardCar.Begin();
        }
Ejemplo n.º 35
0
        private void Sb_Completed(object sender, EventArgs e)
        {
            System.Windows.Media.Animation.Storyboard sb = new System.Windows.Media.Animation.Storyboard();
            double left   = grid.Margin.Left,
                   top    = grid.Margin.Top,
                   right  = grid.Margin.Right,
                   bottom = grid.Margin.Bottom;
            ThicknessAnimation thicknessAnimation = new ThicknessAnimation();

            thicknessAnimation.From     = new Thickness(left, top, right, bottom);
            thicknessAnimation.To       = new Thickness(left + 2000, top, right, bottom);
            thicknessAnimation.Duration = new TimeSpan(0, 0, 0, 0, 800);
            System.Windows.Media.Animation.Storyboard.SetTarget(thicknessAnimation, grid);
            System.Windows.Media.Animation.Storyboard.SetTargetProperty(thicknessAnimation, new PropertyPath("Margin", new object[] { }));
            sb.Children.Add(thicknessAnimation);
            sb.Begin();
        }
Ejemplo n.º 36
0
            public void Go(bool @in, Action completedAction = null)
            {
                var             combinedStoryboard = new AnimationStory();
                var             start          = @in ? _startValue : _endValue;
                var             end            = @in ? _endValue : _startValue;
                IEasingFunction easingFunction = new CircleEase
                {
                    EasingMode = @in ? EasingMode.EaseIn : EasingMode.EaseOut
                };

                var opacityAnimation = new DoubleAnimation(start, end, _animationDuration)
                {
                    EasingFunction = easingFunction
                };

                AnimationStory.SetTarget(opacityAnimation, _dependencyObject);
                AnimationStory.SetTargetProperty(opacityAnimation, new PropertyPath("Opacity"));
                combinedStoryboard.Children.Add(opacityAnimation);

                var scaleAnimationX = new DoubleAnimation(start, end, _animationDuration)
                {
                    EasingFunction = easingFunction
                };

                AnimationStory.SetTarget(scaleAnimationX, _dependencyObject);
                AnimationStory.SetTargetProperty(scaleAnimationX, new PropertyPath("LayoutTransform.Children[0].ScaleX"));
                combinedStoryboard.Children.Add(scaleAnimationX);

                var scaleAnimationY = new DoubleAnimation(start, end, _animationDuration);

                AnimationStory.SetTarget(scaleAnimationY, _dependencyObject);
                AnimationStory.SetTargetProperty(scaleAnimationY, new PropertyPath("LayoutTransform.Children[0].ScaleY"));
                combinedStoryboard.Children.Add(scaleAnimationY);

                combinedStoryboard.Duration = _animationDuration;
                if (completedAction != null)
                {
                    combinedStoryboard.Completed += (o, args) => completedAction();
                }

                combinedStoryboard.Begin();
            }
Ejemplo n.º 37
0
    public static void FlipItem(UIElement over, UIElement under, Directions direction = Directions.LeftToRight, int duration = 200)
    {
        // setup visible plane
        over.Visibility = Visibility.Visible;
        over.Projection = new PlaneProjection {
            CenterOfRotationY = 0
        };
         
        // setup hidden plane
        under.Visibility = Visibility.Collapsed;

        under.Projection = new PlaneProjection {
            CenterOfRotationY = 0
        };
         
        // gen storyboard
        var _StoryBoard = new System.Windows.Media.Animation.Storyboard();
        var _Duration   = TimeSpan.FromMilliseconds(duration);
         
        // add animation: hide-n-show items
        _StoryBoard.Children.Add(CreateVisibility(_Duration, over, false));

        _StoryBoard.Children.Add(CreateVisibility(_Duration, under, true));
         
        // add animation: rotate items
        if (direction == Directions.LeftToRight)
        {
            _StoryBoard.Children.Add(CreateRotation(_Duration, 0, -90, -180, (PlaneProjection)over.Projection));
            _StoryBoard.Children.Add(CreateRotation(_Duration, 180, 90, 0, (PlaneProjection)under.Projection));
        }
        else if (direction == Directions.RightToLeft)
        {
            _StoryBoard.Children.Add(CreateRotation(_Duration, 0, 90, 180, (PlaneProjection)over.Projection));
            _StoryBoard.Children.Add(CreateRotation(_Duration, -180, -90, 0, (PlaneProjection)under.Projection));
        }
         
        // start animation
        _StoryBoard.Begin();
    }
Ejemplo n.º 38
0
 private void Button_Click_1(object sender, RoutedEventArgs e)
 {
     storyboard.Begin();
 }
Ejemplo n.º 39
-26
        public void SetAnimDash(PointCollection pc, ShapeLayer layer)
        {
            MapPolyline animDashLine = new MapPolyline()
            {
                MapStrokeThickness = 20,
                Points = pc,
                ScaleFactor = 0.2
            };

            animDashLine.Stroke = new SolidColorBrush(System.Windows.Media.Color.FromArgb(128, 255, 255, 255));
            animDashLine.StrokeLineJoin = PenLineJoin.Round;
            animDashLine.StrokeStartLineCap = PenLineCap.Flat;
            animDashLine.StrokeEndLineCap = PenLineCap.Triangle;
            animDashLine.StrokeDashCap = PenLineCap.Triangle;
            var dc = new DoubleCollection { 2, 2 };
            animDashLine.IsHitTestVisible = false;
            animDashLine.StrokeDashArray = dc;

            DoubleAnimation animation = new DoubleAnimation
            {
                From = 4,
                To = 0,
                FillBehavior = System.Windows.Media.Animation.FillBehavior.HoldEnd,
                RepeatBehavior = RepeatBehavior.Forever
            };

            var strokeStoryboard = new Storyboard();
            strokeStoryboard.Children.Add(animation);
            Storyboard.SetTargetProperty(animation, new PropertyPath("(Line.StrokeDashOffset)"));
            Storyboard.SetTarget(animation, animDashLine);
            strokeStoryboard.Begin();
            layer.Shapes.Add(animDashLine);
        }