Example #1
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();
            }
Example #2
0
File: Test.cs Project: dfr0/moon
		void RunTest ()
		{
			// Hold the Storyboard with a strong ref and the target with a weak ref.

			WeakControl = new ContentControl ();
			Storyboard = new Storyboard ();
			DoubleAnimation anim = new DoubleAnimation { From = 0, To = 1, Duration = new Duration (TimeSpan.FromSeconds (1)) };
			Storyboard.SetTarget (Storyboard, WeakControl);
			Storyboard.SetTargetProperty (Storyboard, new PropertyPath ("Opacity"));
			Storyboard.Children.Add (anim);

			Storyboard.Begin ();
			
			GCAndInvoke (() => {
				if (WeakControl != null)
					Fail ("Storyboard target should be GC'ed");
				else
					Succeed ();
			});
		}
        public override void Begin(Action completionAction)
        {
            Storyboard = new Storyboard();

            double liCounter = 0;
            var listBoxItems = ListBox.GetVisualDescendants().OfType<ListBoxItem>().Where(lbi => IsOnCurrentPage(lbi) && lbi.IsEnabled).ToList();
            
            if (HoldSelectedItem && Direction == Directions.Out && ListBox.SelectedItem != null)
            {
                //move selected container to end
                var selectedContainer = ListBox.ItemContainerGenerator.ContainerFromItem(ListBox.SelectedItem);
                listBoxItems.Remove(selectedContainer);
                listBoxItems.Add(selectedContainer);
            }

            foreach (ListBoxItem li in listBoxItems)
            {
                GeneralTransform gt = li.TransformToVisual(RootElement);
                Point globalCoords = gt.Transform(new Point(0, 0));
                double heightAdjustment = li.Content is FrameworkElement ? ((li.Content as FrameworkElement).ActualHeight / 2) : (li.ActualHeight / 2);
                //double yCoord = globalCoords.Y + ((((System.Windows.FrameworkElement)(((System.Windows.Controls.ContentControl)(li)).Content)).ActualHeight) / 2);
                double yCoord = globalCoords.Y + heightAdjustment;

                double offsetAmount = (RootElement.ActualHeight / 2) - yCoord;

                PlaneProjection pp = new PlaneProjection();
                pp.GlobalOffsetY = offsetAmount * -1;
                pp.CenterOfRotationX = 0;
                li.Projection = pp;

                CompositeTransform ct = new CompositeTransform();
                ct.TranslateY = offsetAmount;
                li.RenderTransform = ct;

                var beginTime = TimeSpan.FromMilliseconds((FeatherDelay * liCounter) + InitialDelay);

                if (Direction == Directions.In)
                {
                    li.Opacity = 0;

                    DoubleAnimationUsingKeyFrames daukf = new DoubleAnimationUsingKeyFrames();

                    EasingDoubleKeyFrame edkf1 = new EasingDoubleKeyFrame();
                    edkf1.KeyTime = beginTime;
                    edkf1.Value = Angle;
                    daukf.KeyFrames.Add(edkf1);

                    EasingDoubleKeyFrame edkf2 = new EasingDoubleKeyFrame();
                    edkf2.KeyTime = TimeSpan.FromMilliseconds(Duration).Add(beginTime);
                    edkf2.Value = 0;

                    ExponentialEase ee = new ExponentialEase();
                    ee.EasingMode = EasingMode.EaseOut;
                    ee.Exponent = 6;

                    edkf2.EasingFunction = ee;
                    daukf.KeyFrames.Add(edkf2);

                    Storyboard.SetTarget(daukf, li);
                    Storyboard.SetTargetProperty(daukf, new PropertyPath("(UIElement.Projection).(PlaneProjection.RotationY)"));
                    Storyboard.Children.Add(daukf);

                    DoubleAnimation da = new DoubleAnimation();
                    da.Duration = TimeSpan.FromMilliseconds(0);
                    da.BeginTime = beginTime;
                    da.To = 1;

                    Storyboard.SetTarget(da, li);
                    Storyboard.SetTargetProperty(da, new PropertyPath("(UIElement.Opacity)"));
                    Storyboard.Children.Add(da);
                }
                else
                {
                    li.Opacity = 1;

                    DoubleAnimation da = new DoubleAnimation();
                    da.BeginTime = beginTime;
                    da.Duration = TimeSpan.FromMilliseconds(Duration);
                    da.To = Angle;

                    ExponentialEase ee = new ExponentialEase();
                    ee.EasingMode = EasingMode.EaseIn;
                    ee.Exponent = 6;

                    da.EasingFunction = ee;

                    Storyboard.SetTarget(da, li);
                    Storyboard.SetTargetProperty(da, new PropertyPath("(UIElement.Projection).(PlaneProjection.RotationY)"));
                    Storyboard.Children.Add(da);

                    da = new DoubleAnimation();
                    da.Duration = TimeSpan.FromMilliseconds(10);
                    da.To = 0;
                    da.BeginTime = TimeSpan.FromMilliseconds(Duration).Add(beginTime);

                    Storyboard.SetTarget(da, li);
                    Storyboard.SetTargetProperty(da, new PropertyPath("(UIElement.Opacity)"));
                    Storyboard.Children.Add(da);
                }

                liCounter++;
            }

            base.Begin(completionAction);
        }
Example #4
0
        /// <summary>
        /// Event launched when ScatterViewItem's white borders are fully visible.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void stb_border_Completed(object sender, EventArgs e)
        {
            MainDesktop.Sessions.Items.Remove(SessionVM.SessionSVI);
            MainDesktop.Photos.Items.Add(SessionVM.SessionSVI);

            if (SessionVM.Orientation == "left") MainDesktop.LeftSessionActive = false;
            if (SessionVM.Orientation == "right") MainDesktop.RightSessionActive = false;

            MainDesktop.CheckDesktopToDisplay();

            Storyboard = new Storyboard();
            PointAnimation centerPosAnimation = new PointAnimation();
            DoubleAnimation orientationAnimation = new DoubleAnimation();

            ExponentialEase ease = new ExponentialEase();
            ease.EasingMode = EasingMode.EaseOut;
            ease.Exponent = 1.5;

            Random r = new Random();
            Point newCenter = new Point(r.Next((int)MainDesktop.Photos.ActualWidth), r.Next((int)MainDesktop.Photos.ActualHeight));
            Double newOrientation = r.Next(-180, 180);

            if (SessionVM.Orientation == "right" && MainDesktop.LeftSessionActive)
                centerPosAnimation.From = new Point(SessionVM.SessionSVI.ActualCenter.X - 607.5, SessionVM.SessionSVI.ActualCenter.Y);
            else centerPosAnimation.From = SessionVM.SessionSVI.ActualCenter;
            centerPosAnimation.To = newCenter;
            centerPosAnimation.Duration = new Duration(TimeSpan.FromSeconds(5));
            centerPosAnimation.DecelerationRatio = .9;
            centerPosAnimation.EasingFunction = ease;
            centerPosAnimation.FillBehavior = FillBehavior.Stop;
            Storyboard.Children.Add(centerPosAnimation);
            Storyboard.SetTarget(centerPosAnimation, SessionVM.SessionSVI);
            Storyboard.SetTargetProperty(centerPosAnimation, new PropertyPath(ScatterViewItem.CenterProperty));

            orientationAnimation.From = SessionVM.SessionSVI.ActualOrientation;
            orientationAnimation.To = newOrientation;
            orientationAnimation.Duration = new Duration(TimeSpan.FromSeconds(5));
            orientationAnimation.DecelerationRatio = .9;
            orientationAnimation.EasingFunction = ease;
            orientationAnimation.FillBehavior = FillBehavior.Stop;
            Storyboard.Children.Add(orientationAnimation);
            Storyboard.SetTarget(orientationAnimation, SessionVM.SessionSVI);
            Storyboard.SetTargetProperty(orientationAnimation, new PropertyPath(ScatterViewItem.OrientationProperty));

            SessionVM.SessionSVI.Center = newCenter;
            SessionVM.SessionSVI.Orientation = newOrientation;

            Storyboard.Begin();

            SessionVM.SessionSVI.CanMove = true;
            SessionVM.SessionSVI.CanRotate = true;
            SessionVM.SessionSVI.CanScale = false;

            SessionVM.SessionSVI.PreviewTouchDown += new EventHandler<System.Windows.Input.TouchEventArgs>(Session_PreviewTouchDown);
            SessionVM.Reduced = true;
        }
        /// <summary>
        /// adds a looping opacity animation to item
        /// </summary>
        /// <param name="item"></param>
        private Storyboard AddAnimation(ScatterViewItem item)
        {
            DoubleAnimation Animation = new DoubleAnimation();
            Animation.From = 1.0;
            Animation.To = 0.02;
            //Duration needs to divide the timer length(set in Menu.Menu) evenly for the animation to be smooth
            Animation.Duration = new Duration(TimeSpan.FromSeconds(7.5));
            Animation.AutoReverse = true;
            Animation.RepeatBehavior = RepeatBehavior.Forever;

            Storyboard Storyboard = new Storyboard();
            Storyboard.Children.Add(Animation);
            Storyboard.SetTarget(Animation, item);
            Storyboard.SetTargetProperty(Animation, new PropertyPath(ScatterViewItem.OpacityProperty));
            Storyboard.Begin();
            return Storyboard;
        }
Example #6
0
        public WpfSpinButton()
        {
            Width = 25;
            Height = 25;
            Background = new SolidColorBrush (Colors.White);
            Storyboard = new Storyboard { RepeatBehavior = RepeatBehavior.Forever, Duration = TimeSpan.FromMilliseconds (Duration) };

            for (int i = 0; i < 360; i += 30) {
                // Create the rectangle and centre it in our widget
                var rect = new WpfRectangle { Width = 2, Height = 8, Fill = new SolidColorBrush (Colors.Black), RadiusX = 1, RadiusY = 1, Opacity = Values[0] };
                WpfCanvas.SetTop (rect, (Height - rect.Height) / 2);
                WpfCanvas.SetLeft (rect, Width / 2);

                // Rotate the element by 'i' degrees, creating a circle out of all the elements
                var group = new TransformGroup ();
                group.Children.Add (new RotateTransform (i, 0.5, -6));
                group.Children.Add (new TranslateTransform (0, 10));
                rect.RenderTransform = group;

                // Set the animation
                var timeline = new DoubleAnimationUsingKeyFrames ();
                Storyboard.SetTarget (timeline, rect);
                Storyboard.SetTargetProperty (timeline, new PropertyPath ("Opacity"));

                var offset = Duration * (i / 360.0);
                for (int j = 0; j < StartTimes.Length; j++) {
                    var start = (StartTimes[j] + offset) % Duration;
                    timeline.KeyFrames.Add (new EasingDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan (TimeSpan.FromMilliseconds (start)), Value = Values[j] });
                }
                Storyboard.Children.Add (timeline);
                Children.Add (rect);
            }
        }
        public override void Begin(Action completionAction)
        {
            Storyboard = new Storyboard();

            double liCounter = 0;
            var listBoxItems = GetEffectiveItems(RootElement as FrameworkElement);

            foreach (FrameworkElement li in listBoxItems)
            {
                DependencyObject obj = RootElement.Parent;
                AdjustPerspective(li, (obj as FrameworkElement), true);

                var beginTime = TimeSpan.FromMilliseconds((FeatherDelay * liCounter) + InitialDelay);

                if (Direction == Directions.In)
                {
                    li.Opacity = 0;

                    DoubleAnimationUsingKeyFrames daukf = new DoubleAnimationUsingKeyFrames();

                    EasingDoubleKeyFrame edkf1 = new EasingDoubleKeyFrame();
                    edkf1.KeyTime = beginTime;
                    edkf1.Value = Angle;
                    daukf.KeyFrames.Add(edkf1);

                    EasingDoubleKeyFrame edkf2 = new EasingDoubleKeyFrame();
                    edkf2.KeyTime = TimeSpan.FromMilliseconds(Duration).Add(beginTime);
                    edkf2.Value = 0;

                    ExponentialEase ee = new ExponentialEase();
                    ee.EasingMode = EasingMode.EaseOut;
                    ee.Exponent = 6;

                    edkf2.EasingFunction = ee;
                    daukf.KeyFrames.Add(edkf2);

                    Storyboard.SetTarget(daukf, li);
                    Storyboard.SetTargetProperty(daukf, new PropertyPath("(UIElement.Projection).(PlaneProjection.RotationY)"));
                    Storyboard.Children.Add(daukf);

                    DoubleAnimation da = new DoubleAnimation();
                    da.Duration = TimeSpan.FromMilliseconds(0);
                    da.BeginTime = beginTime;
                    da.To = 1;

                    Storyboard.SetTarget(da, li);
                    Storyboard.SetTargetProperty(da, new PropertyPath("(UIElement.Opacity)"));
                    Storyboard.Children.Add(da);
                }
                else
                {
                    li.Opacity = 1;

                    DoubleAnimation da = new DoubleAnimation();
                    da.BeginTime = beginTime;
                    da.Duration = TimeSpan.FromMilliseconds(Duration);
                    da.To = Angle;

                    ExponentialEase ee = new ExponentialEase();
                    ee.EasingMode = EasingMode.EaseIn;
                    ee.Exponent = 6;

                    da.EasingFunction = ee;

                    Storyboard.SetTarget(da, li);
                    Storyboard.SetTargetProperty(da, new PropertyPath("(UIElement.Projection).(PlaneProjection.RotationY)"));
                    Storyboard.Children.Add(da);

                    da = new DoubleAnimation();
                    da.Duration = TimeSpan.FromMilliseconds(10);
                    da.To = 0;
                    da.BeginTime = TimeSpan.FromMilliseconds(Duration).Add(beginTime);

                    Storyboard.SetTarget(da, li);
                    Storyboard.SetTargetProperty(da, new PropertyPath("(UIElement.Opacity)"));
                    Storyboard.Children.Add(da);
                }

                liCounter++;
            }

            base.Begin(completionAction);
        }