Exemple #1
0
        public void UpdateWindowPosition()
        {
            var taskbarState = TaskbarService.GetWinTaskbarState();

            switch (taskbarState.TaskbarPosition)
            {
            case TaskbarPosition.Left:
                Left = (taskbarState.TaskbarSize.right / this.DpiWidthFactor());
                Top  = (taskbarState.TaskbarSize.bottom / this.DpiHeightFactor()) - Height;
                break;

            case TaskbarPosition.Right:
                Left = (taskbarState.TaskbarSize.left / this.DpiWidthFactor()) - Width;
                Top  = (taskbarState.TaskbarSize.bottom / this.DpiHeightFactor()) - Height;
                break;

            case TaskbarPosition.Top:
                Left = (taskbarState.TaskbarSize.right / this.DpiWidthFactor()) - Width;
                Top  = (taskbarState.TaskbarSize.bottom / this.DpiHeightFactor());
                break;

            case TaskbarPosition.Bottom:
                Left = (taskbarState.TaskbarSize.right / this.DpiWidthFactor()) - Width;
                Top  = (taskbarState.TaskbarSize.top / this.DpiHeightFactor()) - Height;
                break;
            }
        }
Exemple #2
0
        private static Interop.AccentFlags GetAccentFlagsForTaskbarPosition()
        {
            var flags = Interop.AccentFlags.DrawAllBorders;

            switch (TaskbarService.GetWinTaskbarState().TaskbarPosition)
            {
            case TaskbarPosition.Top:
                flags &= ~Interop.AccentFlags.DrawTopBorder;
                break;

            case TaskbarPosition.Bottom:
                flags &= ~Interop.AccentFlags.DrawBottomBorder;
                break;

            case TaskbarPosition.Left:
                flags &= ~Interop.AccentFlags.DrawLeftBorder;
                break;

            case TaskbarPosition.Right:
                flags &= ~Interop.AccentFlags.DrawRightBorder;
                break;
            }

            return(flags);
        }
Exemple #3
0
        private void UpdateWindowPosition()
        {
            LayoutRoot.UpdateLayout();
            LayoutRoot.Measure(new Size(double.PositiveInfinity, MaxHeight));
            Height = LayoutRoot.DesiredSize.Height;

            var taskbarState = TaskbarService.GetWinTaskbarState();

            switch (taskbarState.TaskbarPosition)
            {
            case TaskbarPosition.Left:
                Left = (taskbarState.TaskbarSize.right / this.DpiWidthFactor());
                Top  = (taskbarState.TaskbarSize.bottom / this.DpiHeightFactor()) - Height;
                break;

            case TaskbarPosition.Right:
                Left = (taskbarState.TaskbarSize.left / this.DpiWidthFactor()) - Width;
                Top  = (taskbarState.TaskbarSize.bottom / this.DpiHeightFactor()) - Height;
                break;

            case TaskbarPosition.Top:
                Left = (taskbarState.TaskbarSize.right / this.DpiWidthFactor()) - Width;
                Top  = (taskbarState.TaskbarSize.bottom / this.DpiHeightFactor());
                break;

            case TaskbarPosition.Bottom:
                Left = (taskbarState.TaskbarSize.right / this.DpiWidthFactor()) - Width;
                Top  = (taskbarState.TaskbarSize.top / this.DpiHeightFactor()) - Height;
                break;
            }
        }
        public static void ShowWithAnimation(this Window window)
        {
            if (showAnimationInProgress)
            {
                return;
            }

            try
            {
                showAnimationInProgress = true;
                window.Visibility       = Visibility.Visible;
                window.Topmost          = false;
                window.Activate();
                var showAnimation = new DoubleAnimation
                {
                    Duration       = new Duration(TimeSpan.FromSeconds(0.3)),
                    FillBehavior   = FillBehavior.Stop,
                    EasingFunction = new ExponentialEase {
                        EasingMode = EasingMode.EaseOut
                    }
                };
                var taskbarPosition = TaskbarService.GetWinTaskbarState().TaskbarPosition;
                switch (taskbarPosition)
                {
                case TaskbarPosition.Left:
                case TaskbarPosition.Right:
                    showAnimation.To = window.Left;
                    break;

                default:
                    showAnimation.To = window.Top;
                    break;
                }
                showAnimation.From       = (taskbarPosition == TaskbarPosition.Top || taskbarPosition == TaskbarPosition.Left) ? showAnimation.To - 60 : showAnimation.To + 60;
                showAnimation.Completed += (s, e) =>
                {
                    window.Topmost          = true;
                    showAnimationInProgress = false;
                    window.Focus();
                };
                switch (taskbarPosition)
                {
                case TaskbarPosition.Left:
                case TaskbarPosition.Right:
                    window.ApplyAnimationClock(Window.LeftProperty, showAnimation.CreateClock());
                    break;

                default:
                    window.ApplyAnimationClock(Window.TopProperty, showAnimation.CreateClock());
                    break;
                }
            }
            catch
            {
                showAnimationInProgress = false;
            }
        }
        public static void HideWithAnimation(this Window window)
        {
            if (hideAnimationInProgress)
            {
                return;
            }

            try
            {
                hideAnimationInProgress = true;

                var hideAnimation = new DoubleAnimation
                {
                    Duration       = new Duration(TimeSpan.FromSeconds(0.2)),
                    FillBehavior   = FillBehavior.Stop,
                    EasingFunction = new ExponentialEase {
                        EasingMode = EasingMode.EaseIn
                    }
                };
                var taskbarPosition = TaskbarService.GetWinTaskbarState().TaskbarPosition;
                switch (taskbarPosition)
                {
                case TaskbarPosition.Left:
                case TaskbarPosition.Right:
                    hideAnimation.From = window.Left;
                    break;

                default:
                    hideAnimation.From = window.Top;
                    break;
                }
                hideAnimation.To         = (taskbarPosition == TaskbarPosition.Top || taskbarPosition == TaskbarPosition.Left) ? hideAnimation.From - 30 : hideAnimation.From + 30;
                hideAnimation.Completed += (s, e) =>
                {
                    window.Visibility       = Visibility.Hidden;
                    hideAnimationInProgress = false;
                };

                switch (taskbarPosition)
                {
                case TaskbarPosition.Left:
                case TaskbarPosition.Right:
                    window.ApplyAnimationClock(Window.LeftProperty, hideAnimation.CreateClock());
                    break;

                default:
                    window.ApplyAnimationClock(Window.TopProperty, hideAnimation.CreateClock());
                    break;
                }
            }
            catch
            {
                hideAnimationInProgress = false;
            }
        }