Begin() public method

public Begin ( ) : void
return void
        private void StartAnimation(EasingFunctionBase easingFunction)
        {
            // show the chart
            chartControl.Draw(easingFunction);

            // animation
#if WPF
            NameScope.SetNameScope(translate1, new NameScope());
#endif

            var storyboard = new Storyboard();
            var ellipseMove = new DoubleAnimation();
            ellipseMove.EasingFunction = easingFunction;
            ellipseMove.Duration = new Duration(TimeSpan.FromSeconds(AnimationTimeSeconds));
            ellipseMove.From = 0;
            ellipseMove.To = 460;
#if WPF
            Storyboard.SetTargetName(ellipseMove, nameof(translate1));
            Storyboard.SetTargetProperty(ellipseMove, new PropertyPath(TranslateTransform.XProperty));
#else
            Storyboard.SetTarget(ellipseMove, translate1);
            Storyboard.SetTargetProperty(ellipseMove, "X");
#endif

            ellipseMove.BeginTime = TimeSpan.FromSeconds(0.5); // start animation in 0.5 seconds
            ellipseMove.FillBehavior = FillBehavior.HoldEnd; // keep position after animation

            storyboard.Children.Add(ellipseMove);
#if WPF
            storyboard.Begin(this);
#else
            storyboard.Begin();
#endif
        }
        public static void Animate(this UIElement element, double from, double to, double fullDistance)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            var transform = new TranslateTransform();
            element.RenderTransform = transform;

            var xAnimation = new DoubleAnimation
            {
                From = from,
                Duration = TimeSpan.FromMilliseconds(GetAnimationSpeed(from, to, fullDistance)),
                To = to,
                EnableDependentAnimation = true,
                EasingFunction = new SineEase() { EasingMode = EasingMode.EaseOut }
            };

            Storyboard.SetTarget(xAnimation, transform);
            Storyboard.SetTargetProperty(xAnimation, "X");

            var storyboard = new Storyboard();
            storyboard.Children.Add(xAnimation);

            storyboard.Begin();
        }
        public void AnimateVertexForward(VertexControl target)
        {
            var transform = CustomHelper.GetScaleTransform(target);
            if (transform == null)
            {
                target.RenderTransform = new ScaleTransform();
                transform = target.RenderTransform as ScaleTransform;
                if (CenterScale)
                    target.RenderTransformOrigin = new Point(.5, .5);
                else
                    target.RenderTransformOrigin = new Point(0, 0);
            }

            var sb = new Storyboard();
            var scaleAnimation = new DoubleAnimation { Duration = new Duration(TimeSpan.FromSeconds(Duration)), From = 1, To = ScaleTo };
            Storyboard.SetTarget(scaleAnimation, target);
            Storyboard.SetTargetProperty(scaleAnimation, "(UIElement.RenderTransform).(CompositeTransform.ScaleX)");
            sb.Children.Add(scaleAnimation);
            scaleAnimation = new DoubleAnimation { Duration = new Duration(TimeSpan.FromSeconds(Duration)), From = 1, To = ScaleTo };
            Storyboard.SetTarget(scaleAnimation, target);
            Storyboard.SetTargetProperty(scaleAnimation, "(UIElement.RenderTransform).(CompositeTransform.ScaleY)");
            sb.Children.Add(scaleAnimation);

            //transform.BeginAnimation(ScaleTransform.ScaleXProperty, scaleAnimation);
            //transform.BeginAnimation(ScaleTransform.ScaleYProperty, scaleAnimation);
            sb.Begin();
        }
Beispiel #4
0
        internal void Start(PlotElement pe)
        {
            int length = ((IDataSeriesInfo)pe.DataPoint.Series).GetValues().GetLength(1);

            if (SymbolStyle != null)
            {
                pe.Style = SymbolStyle;
            }
            if (Storyboard != null)
            {
                Windows.UI.Xaml.Media.Animation.Storyboard storyboard = Storyboard.DeepClone <Windows.UI.Xaml.Media.Animation.Storyboard>();
                if (storyboard != null)
                {
                    foreach (Timeline timeline in Storyboard.Children)
                    {
                        Timeline element        = timeline.DeepClone <Timeline>();
                        string   targetProperty = Windows.UI.Xaml.Media.Animation.Storyboard.GetTargetProperty(timeline);
                        Windows.UI.Xaml.Media.Animation.Storyboard.SetTargetProperty(element, targetProperty);
                        double indexDelay = GetIndexDelay(timeline);
                        if (indexDelay != 0.0)
                        {
                            double num3 = ((pe.DataPoint.PointIndex * indexDelay) * element.Duration.TimeSpan.TotalSeconds) / ((double)length);
                            element.BeginTime = new TimeSpan?(TimeSpan.FromSeconds(num3));
                        }
                        storyboard.Children.Add(element);
                    }
                    Windows.UI.Xaml.Media.Animation.Storyboard.SetTarget(storyboard, pe);
                    storyboard.Begin();
                }
            }
        }
        private void UIElement_OnPointerEntered(object sender, PointerRoutedEventArgs e)
        {
            var border = (Border)sender;

            // Somehow ZIndex doesn't work in the UniformGrid
            // Perhaps if Jupiter had a method called Panel.GetVisualChild available to override...
            // See: http://blog.pixelingene.com/2007/12/controlling-z-index-of-children-in-custom-controls/
            //Canvas.SetZIndex(border, ++_maxZIndex);
            var sb = new Storyboard();

            var a1 = new DoubleAnimation();
            a1.Duration = TimeSpan.FromSeconds(0.2);
            a1.To = 0.9;
            a1.EasingFunction = new PowerEase { Power = 2, EasingMode = EasingMode.EaseOut };
            Storyboard.SetTarget(a1, border.RenderTransform);
            Storyboard.SetTargetProperty(a1, "ScaleX");
            sb.Children.Add(a1);

            var a2 = new DoubleAnimation();
            a2.Duration = TimeSpan.FromSeconds(0.2);
            a2.To = 0.9;
            a2.EasingFunction = new PowerEase { Power = 2, EasingMode = EasingMode.EaseOut };
            Storyboard.SetTarget(a2, border.RenderTransform);
            Storyboard.SetTargetProperty(a2, "ScaleY");
            sb.Children.Add(a2);

            sb.Begin();
        }
Beispiel #6
0
        /// <summary>
        /// Starts new animation from given images. 
        /// </summary>
        /// <param name="imageNames">Names of images in assets folder</param>
        /// <param name="interval">Interval between animation frames</param>
        public void StartAnimation(IEnumerable<string> imageNames, TimeSpan interval)
        {
            Storyboard storyboard = new Storyboard();
            ObjectAnimationUsingKeyFrames animation = new ObjectAnimationUsingKeyFrames();

            // We're going to animate image inside our control.
            Storyboard.SetTarget(animation, image);
            // Animation relies on changing value of property source
            Storyboard.SetTargetProperty(animation, nameof(image.Source));

            TimeSpan currentInterval = TimeSpan.FromMilliseconds(0);
            foreach (string imageName in imageNames)
            {
                // We're creating individual frames from given images
                ObjectKeyFrame keyFrame = new DiscreteObjectKeyFrame();
                keyFrame.Value = CreateImageFromAssets(imageName);
                keyFrame.KeyTime = currentInterval;
                animation.KeyFrames.Add(keyFrame);
                currentInterval = currentInterval.Add(interval);
            }

            // We're configuring our storyboard which will play animations
            storyboard.RepeatBehavior = RepeatBehavior.Forever;
            storyboard.AutoReverse = true;
            storyboard.Children.Add(animation);
            storyboard.Begin();
        }
Beispiel #7
0
        public void MoveTo(Point from, Point to, EventHandler<object> completed = null)
        {
            TranslateTransform trans = new TranslateTransform();

            _participant.Name = "MyTarget";
            _participant.RenderTransform = trans;

            DoubleAnimation anim1 = new DoubleAnimation() { From = from.X, To = to.X, Duration = TimeSpan.FromMilliseconds(Utility.GAME_TICK_MS - 1) };
            DoubleAnimation anim2 = new DoubleAnimation() { From = from.Y, To = to.Y, Duration = TimeSpan.FromMilliseconds(Utility.GAME_TICK_MS - 1) };

            Storyboard.SetTarget(anim1, _participant);
            Storyboard.SetTargetName(anim1, _participant.Name);
            Storyboard.SetTargetProperty(anim1, "(Canvas.Left)");

            Storyboard.SetTarget(anim2, _participant);
            Storyboard.SetTargetName(anim2, _participant.Name);
            Storyboard.SetTargetProperty(anim2, "(Canvas.Top)");

            Storyboard sb = new Storyboard();
            sb.Children.Add(anim1);
            sb.Children.Add(anim2);

            if (completed == null)
                sb.Completed += (object sender, object e) => { };
            else
                sb.Completed += completed;

            sb.Begin();
        }
Beispiel #8
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, "Opacity");

                sb.Children.Add(fadeIn);

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

                sb.Completed += this.OnFadeInCompleted;

                sb.Begin();
            }
        }
Beispiel #9
0
        /// <summary>
        /// Begint een nieuw storyboard dat het menu grid uitschuift of inschuift naar een positieve (zichtbaar) of negatieve (onzichtbaar) margin.
        /// </summary>
        public void BeginMenuAnimatie()
        {
            Storyboard storyboard = new Storyboard();
            TranslateTransform beweegTransformatie = new TranslateTransform();
            menu.RenderTransform = beweegTransformatie;
            DoubleAnimation verplaatsMenuAnimatie = new DoubleAnimation();
            verplaatsMenuAnimatie.Duration = new Duration(TimeSpan.FromSeconds(0.15));
            if (btnHideShow.Content.Equals(">"))
            {
                verplaatsMenuAnimatie.To = 303;
                verplaatsMenuAnimatie.From = 0;
                btnHideShow.Content = "<";
            }
            else
            {
                verplaatsMenuAnimatie.To = 0;
                verplaatsMenuAnimatie.From = 303;
                btnHideShow.Content = ">";
            }

            storyboard.Children.Add(verplaatsMenuAnimatie);
            Storyboard.SetTarget(verplaatsMenuAnimatie, beweegTransformatie);
            Storyboard.SetTargetProperty(verplaatsMenuAnimatie, "X");
            storyboard.Begin();
        }
Beispiel #10
0
        static public void AnimateOpacity(FrameworkElement element, double start, double end, double duration)
        {
            element.Opacity = 0;

            Duration animationDuration = new Duration(TimeSpan.FromSeconds(duration));
            DoubleAnimation opacityAnimation = new DoubleAnimation();

            opacityAnimation.Duration = animationDuration;
            opacityAnimation.From = start;
            opacityAnimation.To = end;

            Storyboard sb = new Storyboard();
            sb.Duration = animationDuration;

            sb.Children.Add(opacityAnimation);

            Storyboard.SetTarget(opacityAnimation, element);

            // Set the X and Y properties of the Transform to be the target properties
            // of the two respective DoubleAnimations.
            Storyboard.SetTargetProperty(opacityAnimation, "Opacity");

            // Begin the animation.
            sb.Begin();
        }
 public static void BeginAnimation(this DependencyObject target, Timeline animation, string path)
 {
     var sb = new Storyboard();
     Storyboard.SetTarget(animation, target);
     Storyboard.SetTargetProperty(animation, path);
     sb.Children.Add(animation);
     sb.Begin();
 }
 private static void BeginAnimation(DependencyObject obj, string property, Timeline animation)
 {
     Storyboard.SetTargetProperty(animation, property);
     Storyboard.SetTarget(animation, obj);
     var storyboard = new Storyboard();
     storyboard.Children.Add(animation);
     storyboard.Begin();
 }
Beispiel #13
0
        private static void ShowUpAnimation(UIElement element)
        {
            var animation = new PointerUpThemeAnimation();
            Storyboard.SetTarget(animation, element);

            var storyboard = new Storyboard();
            storyboard.Children.Add(animation);
            storyboard.Begin();
        }
Beispiel #14
0
		public static void Flip(UIElement ctrl, UIElement frontCtrl, UIElement backCtrl, TimeSpan duration, bool transitionToBack, Action completed = null)
		{
			duration = new TimeSpan(duration.Ticks / 2);
			var proj = ctrl.Projection is PlaneProjection ? (PlaneProjection)ctrl.Projection : new PlaneProjection();
			if (ctrl.Projection != proj)
				ctrl.Projection = proj;

			var animation = new DoubleAnimation();
			animation.From = 0.0;
			animation.To = 90.0 * (transitionToBack ? 1 : -1);
			animation.Duration = new Duration(duration);

			var story = new Storyboard();
			story.Children.Add(animation);

			Storyboard.SetTarget(animation, proj);
			Storyboard.SetTargetProperty(animation, "RotationY");

			story.Completed += delegate
			{
				animation = new DoubleAnimation();
				animation.From = 270.0 * (transitionToBack ? 1 : -1);
				animation.To = 360.0 * (transitionToBack ? 1 : -1);
				animation.Duration = new Duration(duration);

				story = new Storyboard();
				story.Children.Add(animation);

				Storyboard.SetTarget(animation, proj);
				Storyboard.SetTargetProperty(animation, "RotationY");

				frontCtrl.Visibility = transitionToBack ? Visibility.Collapsed : Visibility.Visible;
				backCtrl.Visibility = !transitionToBack ? Visibility.Collapsed : Visibility.Visible;

				story.Completed += delegate
				{
					proj.RotationY = 0.0;
					if (completed != null)
						completed();
				};
				story.Begin();
			};
			story.Begin();
		}
Beispiel #15
0
        public static void FadeIn(UIElement element)
        {
            element.Visibility = Visibility.Visible;
            var fadeInStoryboard = new Storyboard();
            var fadeInAnimation = new FadeInThemeAnimation();

            Storyboard.SetTarget(fadeInAnimation, element);
            fadeInStoryboard.Children.Add(fadeInAnimation);
            fadeInStoryboard.Begin();
        }
Beispiel #16
0
        public static void FadeOut(UIElement element)
        {
            var fadeOutStoryboard = new Storyboard();
            var fadeOutAnimation = new FadeOutThemeAnimation();

            Storyboard.SetTarget(fadeOutAnimation, element);
            fadeOutStoryboard.Children.Add(fadeOutAnimation);
            fadeOutStoryboard.Completed += (sender, o) => element.Visibility = Visibility.Collapsed;
            fadeOutStoryboard.Begin();
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            _dispatcher = Window.Current.Dispatcher;
            _storyboard = Resources["RotatingSquare"] as Storyboard;
            _storyboard.Begin();

            _viewModel = e.Parameter as DashboardViewModel;
            _viewModel.Tweets.CollectionChanged += TweetsCollectionChanged;
            _viewModel.Start();

            DataContext = _viewModel;
        }
Beispiel #18
0
        public void Show()
        {
            //2s之内连续按2次,退出
            if (clickCount > 0)
            {
                if (Completed != null)
                {
                    Completed(true);
                }
            }
            else
            {
                clickCount++;

                if (Completed != null)
                {
                    Completed(false);
                }

                var tips = new JMessboxControl();
                tips.DataContext = this;
                popup.Height = 65;
                popup.Width = 200;
                popup.Margin = new Thickness(140, 380, 0, 0);
                popup.IsOpen = false;
                popup.Child = tips;

                //渐变效果:透明度200毫秒内从0->1
                Storyboard story = new Storyboard();
                DoubleAnimation topAnimation = new DoubleAnimation();
                topAnimation.From = 0;
                topAnimation.To = 1;
                topAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(200));
                Storyboard.SetTarget(topAnimation, tips);
                Storyboard.SetTargetProperty(topAnimation, "(UIElement.Opacity)");

                story.Children.Add(topAnimation);

                popup.IsOpen = true;
                story.Begin();
                //动画延迟2秒
                story.Duration = new Duration(new TimeSpan(0, 0, 2));
                //story.BeginTime = new TimeSpan(0, 0, 0, 0, 1);
                story.Completed += (s1, e1) =>
                {
                    //2s后执行此方法
                    clickCount = 0;
                    popup.IsOpen = false;
                    story.Stop();
                };
            }

        }
 public void Animate2Color(Color c)
 {
     Storyboard story = new Storyboard();
     ColorAnimation animation = new ColorAnimation();
     animation.Duration = TimeSpan.FromMilliseconds(600);
     story.Children.Add(animation);
     animation.EnableDependentAnimation = true;
     Storyboard.SetTarget(animation, _border);
     Storyboard.SetTargetProperty(animation, "(Border.Background).(SolidColorBrush.Color)");
     animation.To = c;
     story.Begin();
 }
Beispiel #20
0
        public static void Appear(FrameworkElement el, int millisecondPostpone = 0)
        {
            if (el.GetType().Name == "SplashScreenView")
            {
                el.Opacity =1.0;
                return;
            }


            DispatchedHandler invokedHandler = new DispatchedHandler(() =>
            {
                TranslateTransform translateTransform = new TranslateTransform();
                el.RenderTransform = translateTransform;
                translateTransform.X = (double)Animation.pixelsMove;
                if (translateTransform != null)
                {
                    SplineDoubleKeyFrame splineDoubleKeyFrame = new SplineDoubleKeyFrame();
                    splineDoubleKeyFrame.KeyTime = TimeSpan.FromMilliseconds((double)(10 + millisecondPostpone));
                    splineDoubleKeyFrame.Value = (double)Animation.pixelsMove;
                    SplineDoubleKeyFrame splineDoubleKeyFrame2 = new SplineDoubleKeyFrame();
                    splineDoubleKeyFrame2.KeyTime = TimeSpan.FromMilliseconds((double)(350 + millisecondPostpone));
                    splineDoubleKeyFrame2.Value = 0.0;
                    splineDoubleKeyFrame2.KeySpline = new KeySpline();
                    splineDoubleKeyFrame2.KeySpline.ControlPoint1 = new Point(0.0, 0.0);
                    splineDoubleKeyFrame2.KeySpline.ControlPoint2 = new Point(0.0, 1.0);
                    DoubleAnimationUsingKeyFrames doubleAnimationUsingKeyFrames = new DoubleAnimationUsingKeyFrames();
                    Storyboard.SetTarget(doubleAnimationUsingKeyFrames, translateTransform);
                    Storyboard.SetTargetProperty(doubleAnimationUsingKeyFrames, "(TranslateTransform.X)");
                    doubleAnimationUsingKeyFrames.KeyFrames.Add(splineDoubleKeyFrame);
                    doubleAnimationUsingKeyFrames.KeyFrames.Add(splineDoubleKeyFrame2);
                    SplineDoubleKeyFrame splineDoubleKeyFrame3 = new SplineDoubleKeyFrame();
                    splineDoubleKeyFrame3.KeyTime = TimeSpan.FromMilliseconds((double)millisecondPostpone);
                    splineDoubleKeyFrame3.Value = 0.0;
                    SplineDoubleKeyFrame splineDoubleKeyFrame4 = new SplineDoubleKeyFrame();
                    splineDoubleKeyFrame4.KeyTime = TimeSpan.FromMilliseconds((double)(300 + millisecondPostpone));
                    splineDoubleKeyFrame4.Value = 1.0;
                    DoubleAnimationUsingKeyFrames doubleAnimationUsingKeyFrames2 = new DoubleAnimationUsingKeyFrames();
                    Storyboard.SetTarget(doubleAnimationUsingKeyFrames2, el);
                    Storyboard.SetTargetProperty(doubleAnimationUsingKeyFrames2, "(UIElement.Opacity)");
                    doubleAnimationUsingKeyFrames2.KeyFrames.Add(splineDoubleKeyFrame3);
                    doubleAnimationUsingKeyFrames2.KeyFrames.Add(splineDoubleKeyFrame4);
                    Storyboard storyboard = new Storyboard();
                    storyboard.Children.Add(doubleAnimationUsingKeyFrames);
                    storyboard.Children.Add(doubleAnimationUsingKeyFrames2);
                    storyboard.Begin();
                }

            });


            el.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, invokedHandler).GetResults();
        }
Beispiel #21
0
 /// <summary>
 /// 显示黑色遮罩
 /// </summary>
 public void ShowMask(bool toShow, bool disableAnimation = false)
 {
     if (disableAnimation)
     {
         Mask.Opacity = toShow ? MAX_OPACITY : 0;
     }
     else
     {
         Storyboard storyboard = new Storyboard();
         StoryboardHelper.CreatAnimation(Mask, storyboard, "UIElement.Opacity", 200, 0, toShow ? MAX_OPACITY : 0, null, false);
         storyboard.Begin();
     }
 }
Beispiel #22
0
        public static void MoveElementOnCanvas(UIElement uiElement, double toX, double toY)
        {
            double fromX = Canvas.GetLeft(uiElement);
            double fromY = Canvas.GetTop(uiElement);

            Storyboard storyboard = new Storyboard();
            DoubleAnimation animationX = CreateDoubleAnimation(uiElement, fromX, toX, "(Canvas.Left)");
            DoubleAnimation animationY = CreateDoubleAnimation(uiElement, fromY, toY, "(Canvas.Top)");

            storyboard.Children.Add(animationX);
            storyboard.Children.Add(animationY);
            storyboard.Begin();
        }
Beispiel #23
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            button.RenderTransform = new CompositeTransform();
              var storyboard = new Storyboard();
              var list = new List<Point>();
              list.Add(new Point(0, 0));
              list.Add(new Point(1000, 1000));
              list.Add(new Point(1000, 500));

              storyboard.AddWayPointAnimation(button, list, 500);

              storyboard.Begin();
        }
Beispiel #24
0
        public static void Animate(DependencyObject target, string property, double from, double to, int duration, EventHandler<object> completed)
        {
            var animation = new DoubleAnimation();
            animation.From = from;
            animation.To = to;
            animation.Duration = new TimeSpan(0, 0, 0, 0, duration);
            Storyboard.SetTarget(animation, target);
            Storyboard.SetTargetProperty(animation, property);

            var storyBoard = new Storyboard();
            storyBoard.Children.Add(animation);
            storyBoard.Completed += completed;
            storyBoard.Begin();
        }
Beispiel #25
0
 private void AnimateEnemy(ContentControl enemy, double from, double to, string propertyToAnimate)
 {
     Storyboard storyboard = new Storyboard() { AutoReverse = true, RepeatBehavior = RepeatBehavior.Forever };
     DoubleAnimation animation = new DoubleAnimation()
     {
         From = from,
         To = to,
         Duration = new Duration(TimeSpan.FromSeconds(random.Next(4, 6)))
     };
     Storyboard.SetTarget(animation, enemy);
     Storyboard.SetTargetProperty(animation, propertyToAnimate);
     storyboard.Children.Add(animation);
     storyboard.Begin();
 }
Beispiel #26
0
 void animateimage(double to, int index)
 {
     Windows.UI.Xaml.Media.Animation.Storyboard      story     = new Windows.UI.Xaml.Media.Animation.Storyboard();
     Windows.UI.Xaml.Media.Animation.DoubleAnimation animation = new Windows.UI.Xaml.Media.Animation.DoubleAnimation();
     animation.Duration = TimeSpan.FromMilliseconds(650);
     story.Children.Add(animation);
     Windows.UI.Xaml.Media.Animation.CubicEase ease1 = new Windows.UI.Xaml.Media.Animation.CubicEase();
     //ease1.EasingMode = Windows.UI.Xaml.Media.Animation.EasingMode.EaseIn ;
     animation.EnableDependentAnimation = true;
     animation.EasingFunction           = ease1;
     animation.To = to;
     Windows.UI.Xaml.Media.Animation.Storyboard.SetTargetProperty(animation, "Opacity");
     Windows.UI.Xaml.Media.Animation.Storyboard.SetTarget(animation, _imagelist[index]);
     story.Begin();
 }
        /// <summary>
        /// Fades the element in using the FadeInThemeAnimation.
        /// </summary>
        /// <remarks>
        /// Opacity property of the element is not affected.<br/>
        /// The duration of the visible animation itself is not affected by the duration parameter. It merely indicates how long the Storyboard will run.<br/>
        /// If FadeOutThemeAnimation was not used on the element before - nothing will happen.<br/>
        /// </remarks>
        /// <param name="element"></param>
        /// <param name="duration"></param>
        /// <returns></returns>
        public static void FadeIn(this UIElement element, TimeSpan? duration = null)
        {
            ((FrameworkElement)element).Visibility = Visibility.Visible;
            var fadeInStoryboard = new Storyboard();
            var fadeInAnimation = new FadeInThemeAnimation();

            if (duration != null)
            {
                fadeInAnimation.Duration = duration.Value;
            }

            Storyboard.SetTarget(fadeInAnimation, element);
            fadeInStoryboard.Children.Add(fadeInAnimation);
            fadeInStoryboard.Begin();
        }
        public Task PlayAsync(Storyboard sb)
        {
            TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
            EventHandler<object> lambda = null;

            lambda = (s, e) =>
            {
                sb.Completed -= lambda;
                tcs.TrySetResult(null);
            };
            sb.Completed += lambda;
            sb.Begin();

            return tcs.Task;
        }
Beispiel #29
0
 private static void SourceChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
 {
     FadingImage instance = (FadingImage)sender;
     instance.ImageA.Source = (ImageSource)args.OldValue;
     instance.ImageB.Source = (ImageSource)args.NewValue;
     DoubleAnimation doubleAnimation = new DoubleAnimation();
     doubleAnimation.From = 0;
     doubleAnimation.To = 1;
     doubleAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(instance.TransitionMilliseconds));
     Storyboard sb = new Storyboard();
     Storyboard.SetTarget(doubleAnimation, instance.ImageB);
     Storyboard.SetTargetProperty(doubleAnimation, "Opacity");
     sb.Children.Add(doubleAnimation);
     sb.Begin();
 }
        public static void AnimatePath(Windows.UI.Xaml.Shapes.Path progressPath, double radius, Point initialPoint, double finalAngle = 180, double timeStep = 0.01)
        {
            var storyboard = new Storyboard();

            var progressAnimation = new ObjectAnimationUsingKeyFrames();
            Storyboard.SetTarget(progressAnimation, progressPath);
            Storyboard.SetTargetProperty(progressAnimation, "(Path.Data)");

            // for a smoother animation
            double multiplier = 3;

            Point center = new Point(radius, radius);
            for (int i = 0; i <= finalAngle * multiplier; i++)
            {
                var discreteObjectKeyFrame = new DiscreteObjectKeyFrame();
                discreteObjectKeyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(i * timeStep));

                // create points for each ArcSegment
                Point firstArcPoint = new Point(radius, 0);
                Point secondArcPoint = new Point(radius, 0);
                Point calculatedPoint = new Point()
                {
                    X = Math.Cos(Math.PI * (270 - i / multiplier) / 180.0) * radius + center.X,
                    Y = Math.Sin(Math.PI * (270 - i / multiplier) / 180.0) * radius + center.Y
                };

                if (i < 180 * multiplier)
                {
                    // use the calculated point for the first and second arc segments
                    firstArcPoint = calculatedPoint;
                    secondArcPoint = calculatedPoint;
                }
                else
                {
                    // leave the first arc segment static and use the calculated point for the second
                    firstArcPoint = new Point() { X = radius, Y = radius * 2 };
                    secondArcPoint = calculatedPoint;
                }

                // for instance, a complete circle with a radius of 150: "m 150,0 A 150,150 0 0 0 150,300 A 150,150 0 0 0 150,0"
                string dataValue = "m {0},{1} A {2},{2} 0 0 0 {3},{4} A {2},{2} 0 0 0 {5},{6}";
                discreteObjectKeyFrame.Value = string.Format(dataValue, initialPoint.X, initialPoint.Y, radius, firstArcPoint.X, firstArcPoint.Y, secondArcPoint.X, secondArcPoint.Y);
                progressAnimation.KeyFrames.Add(discreteObjectKeyFrame);
            }

            storyboard.Children.Add(progressAnimation);
            storyboard.Begin();
        }
        private static void AnimateOpacity(DependencyObject target, double from, double to)
        {
            var opacityAnimation = new DoubleAnimation
            {
                From = from,
                To = to,
                Duration = TimeSpan.FromMilliseconds(500)
            };

            Storyboard.SetTarget(opacityAnimation, target);
            Storyboard.SetTargetProperty(opacityAnimation, "Opacity");

            var storyboard = new Storyboard();
            storyboard.Children.Add(opacityAnimation);
            storyboard.Begin();
        }
Beispiel #32
0
 public static void MakeBeeMove(AnimatedImage bee,
                                double fromX, double toX, double y)
 {
     Canvas.SetTop(bee, y);
     Storyboard storyboard = new Storyboard();
     DoubleAnimation animation = new DoubleAnimation();
     Storyboard.SetTarget(animation, bee);
     Storyboard.SetTargetProperty(animation, "(Canvas.Left)");
     animation.From = fromX;
     animation.To = toX;
     animation.Duration = TimeSpan.FromSeconds(3);
     animation.RepeatBehavior = RepeatBehavior.Forever;
     animation.AutoReverse = true;
     storyboard.Children.Add(animation);
     storyboard.Begin();
 }