示例#1
0
        private void Animate()
        {
            if (ExpandSite != null)
            {
                double toValue   = IsExpanded ? 301 : 0;
                double fromValue = IsExpanded ? 0 : 300;

                if (Settings.Default.EnableAnimations)
                {
                    Duration        duration  = new Duration(TimeSpan.FromMilliseconds(150));
                    DoubleAnimation animation = new DoubleAnimation(toValue, duration);
                    animation.From           = fromValue;
                    animation.Completed     += animation_Completed;
                    animation.EasingFunction = new QuadraticEase {
                        EasingMode = EasingMode.EaseOut
                    };
                    IsAnimating = true;
                    ExpandSite.BeginAnimation(ContentPresenter.WidthProperty, animation);
                }
                else
                {
                    IsAnimating = false;
                    Duration        duration  = new Duration(TimeSpan.FromMilliseconds(0));
                    DoubleAnimation animation = new DoubleAnimation(toValue, duration);
                    animation.From = fromValue;
                    ExpandSite.BeginAnimation(ContentPresenter.WidthProperty, animation);
                }
            }
        }
示例#2
0
 protected void OnNavigating(object sender, NavigatingCancelEventArgs e)
 {
     if (Content != null && !_allowDirectNavigation && _contentPresenter != null)
     {
         e.Cancel = true;
         _navArgs = e;
         _contentPresenter.IsHitTestVisible = false;
         DoubleAnimation da = new DoubleAnimation(0.0d, FadeDuration);
         da.DecelerationRatio = 1.0d;
         da.Completed        += FadeOutCompleted;
         IsEnabled            = false;
         _contentPresenter.BeginAnimation(OpacityProperty, da);
     }
     _allowDirectNavigation = false;
 }
示例#3
0
        private void AnimationClosePresenter_Completed(object sender, EventArgs e)
        {
            if (NowOpen == 1)
            {
                this.OutputView.Content = view1;
            }
            if (NowOpen == 2)
            {
                this.OutputView.Content = view2;
            }
            if (NowOpen == 4)
            {
                this.OutputView.Content = view4;
            }
            if (NowOpen == 5)
            {
                this.OutputView.Content = view5;
            }
            if (NowOpen == 3)
            {
                this.OutputView.Content = view3;
            }
            DoubleAnimation animation = new DoubleAnimation();

            animation.From     = 0;
            animation.To       = 712;
            animation.Duration = TimeSpan.FromMilliseconds(200);
            ContentPresenter.BeginAnimation(Grid.WidthProperty, animation);
        }
示例#4
0
        /// <summary>
        /// Starts the animation for the new content
        /// </summary>
        private void BeginAnimateContentReplacement()
        {
            var newContentTransform = new TranslateTransform();
            var oldContentTransform = new TranslateTransform();

            m_paintArea.RenderTransform   = oldContentTransform;
            m_mainContent.RenderTransform = newContentTransform;
            if (AnimationType == AnimationType.Slide)
            {
                m_paintArea.Visibility = Visibility.Visible;
                if (Direction == AnimationDirection.RightToLeft)
                {
                    newContentTransform.BeginAnimation(TranslateTransform.XProperty, CreateAnimation(ActualWidth, 0, DefaultSlideEasing));
                    oldContentTransform.BeginAnimation(TranslateTransform.XProperty, CreateAnimation(0, -ActualWidth, DefaultSlideEasing, () => m_paintArea.Visibility = Visibility.Hidden));
                }
                else
                {
                    newContentTransform.BeginAnimation(TranslateTransform.XProperty, CreateAnimation(-ActualWidth, 0));
                    oldContentTransform.BeginAnimation(TranslateTransform.XProperty, CreateAnimation(0, ActualWidth, DefaultSlideEasing, () => m_paintArea.Visibility = Visibility.Hidden));
                }
            }
            else if (AnimationType == AnimationType.FadeInOut)
            {
                m_mainContent.Visibility = Visibility.Hidden;
                m_paintArea.BeginAnimation(OpacityProperty, CreateAnimation(1, 0, null, () =>
                {
                    m_paintArea.Opacity      = 0;
                    m_mainContent.Opacity    = 0;
                    m_mainContent.Visibility = Visibility.Visible;

                    m_mainContent.BeginAnimation(OpacityProperty, CreateAnimation(0, 1));
                }));
            }
        }
示例#5
0
        private void Startanimation()
        {
            DoubleAnimation animation = new DoubleAnimation();

            animation.From       = 712;
            animation.To         = 0;
            animation.Duration   = TimeSpan.FromMilliseconds(200);
            animation.Completed += AnimationClosePresenter_Completed;
            ContentPresenter.BeginAnimation(Grid.WidthProperty, animation);
        }
        protected internal override void BeginTransition(TransitionElement transitionElement, ContentPresenter oldContent, ContentPresenter newContent)
        {
            DoubleAnimation da = new DoubleAnimation(0, Duration);

            da.Completed += delegate
            {
                EndTransition(transitionElement, oldContent, newContent);
            };
            oldContent.BeginAnimation(UIElement.OpacityProperty, da);
        }
示例#7
0
 protected void OnNavigating(object sender, NavigatingCancelEventArgs e)
 {
     // if we did not internally initiate the navigation:
     //   1. cancel the navigation,
     //   2. cache the target,
     //   3. disable hittesting during the fade, and
     //   4. fade out the current content
     if (Content != null && !_allowDirectNavigation && _contentPresenter != null)
     {
         e.Cancel = true;
         _navArgs = e;
         _contentPresenter.IsHitTestVisible = false;
         DoubleAnimation da = new DoubleAnimation(0.0d, FadeDuration);
         da.DecelerationRatio = 1.0d;
         da.Completed        += FadeOutCompleted;
         _contentPresenter.BeginAnimation(OpacityProperty, da);
     }
     _allowDirectNavigation = false;
 }
        void FadeTransition()
        {
            _paintArea.Visibility = Visibility.Visible;
            _paintArea.Opacity    = 1;
            _paintArea.InvalidateVisual();
            _paintArea.BeginAnimation(OpacityProperty, new DoubleAnimation(1, 0, new Duration(TimeSpan.FromMilliseconds(this.Duration))));
            var animation = new DoubleAnimation(0, 1, new Duration(TimeSpan.FromMilliseconds(this.Duration)));

            animation.Completed += (s, e) => _paintArea.Visibility = Visibility.Hidden;
            _mainContent.BeginAnimation(OpacityProperty, animation);
        }
示例#9
0
        protected void StartAnimation(Item item)
        {
            ContentPresenter dobj        = (ContentPresenter)itemsControl.ItemContainerGenerator.ContainerFromItem(item);
            double           x           = (double)dobj.GetValue(Canvas.LeftProperty);
            double           y           = (double)dobj.GetValue(Canvas.TopProperty);
            Point            targetPoint = GetTargetPosition(dobj, item);
            double           dist        = Math.Sqrt((x - targetPoint.X) * (x - targetPoint.X) + (y - targetPoint.Y) * (y - targetPoint.Y));
            double           dur         = Math.Pow(dist / 400, 0.5);

            if (dur > 1)
            {
                dur = 1;
            }
            if (dur < 0.1)
            {
                dur = 0.1;
            }
            Duration        duration = new Duration(TimeSpan.FromSeconds(dur));
            DoubleAnimation xanim    = new DoubleAnimation(targetPoint.X, duration);
            DoubleAnimation yanim    = new DoubleAnimation(targetPoint.Y, duration);

            dobj.BeginAnimation(Canvas.LeftProperty, xanim);
            dobj.BeginAnimation(Canvas.TopProperty, yanim);
        }
示例#10
0
        private void ArrangeCollapseElement(int idx, ContentPresenter element,
                                            double panelCenterX, double panelCenterY,
                                            double elementCenterX, double elementCenterY,
                                            double destX, double destY)
        {
            element.Arrange(new Rect(destX, destY, element.DesiredSize.Width, element.DesiredSize.Height));

            var       transGroup = element.RenderTransform as TransformGroup;
            Transform translateTransform, rotateTransform;

            if (transGroup == null)
            {
                element.RenderTransform = transGroup = new TransformGroup();
                translateTransform      = new TranslateTransform();
                rotateTransform         = new RotateTransform()
                {
                    CenterX = elementCenterX, CenterY = elementCenterY
                };

                transGroup.Children.Add(translateTransform);
                transGroup.Children.Add(rotateTransform);
            }
            else
            {
                translateTransform = transGroup.Children[0] as TranslateTransform;
                rotateTransform    = transGroup.Children[1] as RotateTransform;
            }
            element.RenderTransformOrigin = new Point(0.5, 0.5);

            //if (i != 0) continue;

            var aniDuration = AnimationDuration + TimeSpan.FromSeconds(AnimationDurationStep * idx);

            translateTransform.BeginAnimation(TranslateTransform.XProperty, new DoubleAnimation(0, panelCenterX - destX, aniDuration));
            translateTransform.BeginAnimation(TranslateTransform.YProperty, new DoubleAnimation(0, panelCenterY - destY, aniDuration));

            rotateTransform.BeginAnimation(RotateTransform.CenterXProperty, new DoubleAnimation(0, panelCenterX - destX, aniDuration));
            rotateTransform.BeginAnimation(RotateTransform.CenterYProperty, new DoubleAnimation(0, panelCenterY - destY, aniDuration));
            rotateTransform.BeginAnimation(RotateTransform.AngleProperty, new DoubleAnimation(0, -720, aniDuration));

            element.BeginAnimation(OpacityProperty, new DoubleAnimation(1, 0.2, aniDuration));
        }
        private void ResetInternal(UIElement element)
        {
            this.CancelTransition();

            // How to: Set a Property After Animating It with a Storyboard
            // https://docs.microsoft.com/en-us/dotnet/framework/wpf/graphics-multimedia/how-to-set-a-property-after-animating-it-with-a-storyboard
            contentPresenter.BeginAnimation(UIElement.OpacityProperty, null);
            element.BeginAnimation(UIElement.RenderTransformProperty, null);
            element.Opacity = 1.0;
            var group = new TransformGroup
            {
                Children =
                {
                    new ScaleTransform(),
                    new SkewTransform(),
                    new RotateTransform(),
                    new TranslateTransform()
                }
            };

            element.RenderTransform = group;
        }
示例#12
0
        private void BeginAnimateContentReplacement()
        {
            PART_PaintArea.Opacity = 1.0;

            var fadeOutAnimation = new DoubleAnimation
            {
                From        = 1.0,
                To          = 0.0,
                Duration    = new Duration(TimeSpan.FromSeconds(this.Duration)),
                AutoReverse = false
            };

            var fadeInAnimation = new DoubleAnimation
            {
                From        = 0.0,
                To          = 1.0,
                Duration    = new Duration(TimeSpan.FromSeconds(this.Duration)),
                AutoReverse = false
            };

            PART_PaintArea.BeginAnimation(OpacityProperty, fadeOutAnimation);
            PART_MainContent.BeginAnimation(OpacityProperty, fadeInAnimation);
        }
示例#13
0
 protected override void OnTransitionEnded(TransitionElement transitionElement, ContentPresenter oldContent, ContentPresenter newContent)
 {
     oldContent.BeginAnimation(UIElement.OpacityProperty, null);
 }
        protected override void BeginTransition3D(TransitionPresenter transitionElement, ContentPresenter oldContent, ContentPresenter newContent, Viewport3D viewport)
        {
            Size        size           = transitionElement.RenderSize;
            Point3D     rotationCenter = new Point3D(0.5, 0.5, 0);
            Vector3D    rotationAxis   = new Vector3D(-1, 1, 0);
            Transform3D translation    = null;
            double      endAngle       = Angle;

            var g = (PerspectiveCamera)viewport.Camera;

            Console.WriteLine(g.Position);
            ModelVisual3D m1;

            if (OutOrIn == "In")
            {
                //translation = new TranslateTransform3D(0,0,-1);
                //DoubleAnimation y = new DoubleAnimation(0, TimeSpan.FromMilliseconds(300));
                //y.AccelerationRatio = 0.3;
                //y.DecelerationRatio = 0.7;
                //translation.BeginAnimation(TranslateTransform3D.OffsetZProperty, y);

                //DoubleAnimation y2 = new DoubleAnimation(40, TimeSpan.FromMilliseconds(500));
                //y2.From = 900;
                //y2.AccelerationRatio = 0.3;
                //y2.DecelerationRatio = 0.7;
                //translation.BeginAnimation(TranslateTransform3D.OffsetZProperty, y2);

                //translation = new ScaleTransform3D();
                //DoubleAnimation w1 = new DoubleAnimation(1, TimeSpan.FromMilliseconds(600));
                //w1.From = 0.7;
                //w1.AccelerationRatio = 0.8;
                //w1.DecelerationRatio = 0.2;
                //translation.BeginAnimation(ScaleTransform3D.ScaleXProperty, w1);
                //translation.BeginAnimation(ScaleTransform3D.ScaleYProperty, w1);
                //translation.BeginAnimation(ScaleTransform3D.ScaleZProperty, w1);



                translation = new ScaleTransform3D();
                DoubleAnimation w1 = new DoubleAnimation(1, Duration);
                w1.From = 0.7;
                w1.AccelerationRatio = 0.3;
                w1.DecelerationRatio = 0.7;
                translation.BeginAnimation(ScaleTransform3D.ScaleXProperty, w1);
                translation.BeginAnimation(ScaleTransform3D.ScaleYProperty, w1);
                translation.BeginAnimation(ScaleTransform3D.ScaleZProperty, w1);

                DoubleAnimation w2 = new DoubleAnimation(0, 1, Duration);
                newContent.BeginAnimation(FrameworkElement.OpacityProperty, w2);

                rotationCenter           = new Point3D(0.5, 0.5, 0);
                rotationAxis             = new Vector3D(-1, -1, 0);
                endAngle                 = Angle;
                viewport.Children.Add(m1 = MakeSide(newContent, new Point3D(), new Vector3D(size.Width, 0, 0), new Vector3D(0, size.Height, 0), endAngle, rotationCenter, rotationAxis,
                                                    delegate
                {
                    EndTransition(transitionElement, oldContent, newContent);
                }));
                m1.Transform = translation;
            }
            else
            {
                //translation = new TranslateTransform3D();
                //DoubleAnimation y = new DoubleAnimation(-300, Duration);
                //y.From = 0;
                //y.AccelerationRatio = 0.7;
                //y.DecelerationRatio = 0.3;
                //translation.BeginAnimation(TranslateTransform3D.OffsetYProperty, y);

                translation = new ScaleTransform3D();
                DoubleAnimation w1 = new DoubleAnimation(0.7, Duration);
                w1.From = 1;
                w1.AccelerationRatio = 0.7;
                w1.DecelerationRatio = 0.3;
                translation.BeginAnimation(ScaleTransform3D.ScaleXProperty, w1);
                translation.BeginAnimation(ScaleTransform3D.ScaleYProperty, w1);
                translation.BeginAnimation(ScaleTransform3D.ScaleZProperty, w1);

                DoubleAnimation w2 = new DoubleAnimation(1, 0, Duration);
                oldContent.BeginAnimation(FrameworkElement.OpacityProperty, w2);



                rotationCenter           = new Point3D(0.5, 0.5, 0);
                rotationAxis             = new Vector3D(-1, -1, 0);
                endAngle                 = 1 * Angle;
                viewport.Children.Add(m1 = MakeSide(oldContent, new Point3D(), new Vector3D(size.Width, 0, 0), new Vector3D(0, size.Height, 0), endAngle, rotationCenter, rotationAxis,
                                                    delegate
                {
                    EndTransition(transitionElement, oldContent, newContent);
                }));
                m1.Transform = translation;
            }
        }