Пример #1
0
        void CancelSlide(ToastAdorner adorner, double originalLeft, double originalTop, int elapsedTime)
        {
            void Animate()
            {
                var horizontal = LeaveDirection == Direction.Left || LeaveDirection == Direction.Right;

                adorner.BeginAnimation(horizontal ? ToastAdorner.LeftProperty : ToastAdorner.TopProperty, null);
                var animation = new DoubleAnimation(
                    horizontal ? adorner.Left : adorner.Top,
                    horizontal ? originalLeft : originalTop,
                    GetCancelTime(elapsedTime));

                adorner.BeginAnimation(horizontal ? ToastAdorner.LeftProperty : ToastAdorner.TopProperty, animation);
            }

            Application.Current?.Dispatcher?.Invoke((ActionDelegate)Animate);
        }
Пример #2
0
        void CancelFade(ToastAdorner adorner, double originalOpacity)
        {
            void Animate()
            {
                adorner.BeginAnimation(UIElement.OpacityProperty, null);
            }

            Application.Current?.Dispatcher?.Invoke((ActionDelegate)Animate);
            adorner.Opacity = originalOpacity;
        }
Пример #3
0
        void Fade(double originalOpacity, ToastAdornerSettings settings, ToastAdorner adorner)
        {
            void Animate()
            {
                var animation = new DoubleAnimation(
                    originalOpacity,
                    0,
                    GetLeaveTime(settings),
                    FillBehavior.Stop);

                adorner.BeginAnimation(UIElement.OpacityProperty, animation);
            }

            Application.Current?.Dispatcher?.Invoke((ActionDelegate)Animate);
        }
Пример #4
0
        void Slide(ToastAdorner adorner, ToastAdornerSettings settings)
        {
            double targetTop  = 0;
            double targetLeft = 0;

            void SetTargets()
            {
                targetTop  = adorner.Top;
                targetLeft = adorner.Left;

                if (LeaveDirection == Direction.Left)
                {
                    targetLeft = -adorner.ActualWidth;
                }
                else if (LeaveDirection == Direction.Right)
                {
                    targetLeft = GetWidth();
                }
                else if (LeaveDirection == Direction.Up)
                {
                    targetTop = -adorner.ActualHeight;
                }
                else if (LeaveDirection == Direction.Down)
                {
                    targetTop = GetHeight();
                }
                else
                {
                    throw new ArgumentOutOfRangeException();
                }
            }

            Application.Current?.Dispatcher?.Invoke((ActionDelegate)SetTargets);

            void Animate()
            {
                var horizontal = LeaveDirection == Direction.Left || LeaveDirection == Direction.Right;
                var animation  = new DoubleAnimation(
                    horizontal ? adorner.Left : adorner.Top,
                    horizontal ? targetLeft : targetTop,
                    GetLeaveTime(settings),
                    FillBehavior.Stop);

                adorner.BeginAnimation(horizontal ? ToastAdorner.LeftProperty : ToastAdorner.TopProperty, animation);
            }

            Application.Current?.Dispatcher?.Invoke((ActionDelegate)Animate);
        }
Пример #5
0
        void Enter(ToastAdorner toast)
        {
            toast.Top  = GetEntryTop(toast);
            toast.Left = GetEntryLeft(toast);

            if (EnterStyle == EnterStyle.PopIn || EnterStyle == EnterStyle.FadeIn)
            {
                if (EnterLocation == Location.TopLeft ||
                    EnterLocation == Location.TopRight)
                {
                    toast.Top += toast.ActualHeight + VerticalPadding;
                }

                if (EnterLocation == Location.BottomLeft ||
                    EnterLocation == Location.BottomRight)
                {
                    toast.Top -= toast.ActualHeight + VerticalPadding;
                }

                if (EnterLocation == Location.TopLeft ||
                    EnterLocation == Location.BottomLeft)
                {
                    toast.Left += toast.ActualWidth + HorizontalPadding;
                }

                if (EnterLocation == Location.TopRight ||
                    EnterLocation == Location.BottomRight)
                {
                    toast.Left -= toast.ActualWidth + HorizontalPadding;
                }
            }

            if (EnterStyle == EnterStyle.FadeIn)
            {
                toast.Opacity = 0;

                void Animate()
                {
                    var animation = new DoubleAnimation(
                        0,
                        1,
                        MoveDuration,
                        FillBehavior.Stop);

                    toast.BeginAnimation(UIElement.OpacityProperty, animation);
                }

                Application.Current?.Dispatcher?.Invoke((ActionDelegate)Animate);
            }

            if (EnterStyle == EnterStyle.SlideIn)
            {
                double from;
                double target;
                if (EnterFromDirection == Direction.Left)
                {
                    from   = toast.Left;
                    target = toast.Left + toast.ActualWidth + HorizontalPadding + HorizontalAdjustment;
                }
                else if (EnterFromDirection == Direction.Right)
                {
                    from   = toast.Left;
                    target = GetWidth() - toast.ActualWidth - HorizontalPadding + HorizontalAdjustment;
                }
                else if (EnterFromDirection == Direction.Up)
                {
                    from   = toast.Top;
                    target = toast.Top + toast.ActualHeight + VerticalPadding + VerticalAdjustment;
                }
                else // Direction.Down
                {
                    from   = toast.Top;
                    target = GetHeight() - toast.ActualHeight - VerticalPadding + VerticalAdjustment;
                }

                var property =
                    EnterFromDirection == Direction.Left || EnterFromDirection == Direction.Right
                        ? ToastAdorner.LeftProperty
                        : ToastAdorner.TopProperty;

                var animation = new DoubleAnimation(
                    from,
                    target,
                    MoveDuration);

                void Animate()
                {
                    toast.BeginAnimation(property, animation);
                }

                Application.Current?.Dispatcher?.Invoke((ActionDelegate)Animate);
            }

            if (MoveStyle == MoveStyle.Stack)
            {
                if (MoveDirection == Direction.Left)
                {
                    foreach (var adorner in _adorners)
                    {
                        toast.Left -= adorner.ActualWidth + HorizontalPadding;
                    }
                }
                else if (MoveDirection == Direction.Right)
                {
                    foreach (var adorner in _adorners)
                    {
                        toast.Left += adorner.ActualWidth + HorizontalPadding;
                    }
                }
                else if (MoveDirection == Direction.Up)
                {
                    foreach (var adorner in _adorners)
                    {
                        toast.Top -= adorner.ActualHeight + VerticalPadding;
                    }
                }
                else if (MoveDirection == Direction.Down)
                {
                    foreach (var adorner in _adorners)
                    {
                        toast.Top += adorner.ActualHeight + VerticalPadding;
                    }
                }
            }

            if (MoveStyle == MoveStyle.Stack)
            {
                _adorners.Insert(0, toast);
            }
            else
            {
                _adorners.Add(toast);
            }

            if (MoveStyle == MoveStyle.Push)
            {
                MoveForward();
            }
        }