Пример #1
0
        public WpfAppBar(Window window)
        {
            _currentPosition = new Position();
            _window = window;

            // Show/Hide timers.
            _showTimer = new Timer();
            _showTimer.AutoReset = false;
            _showTimer.Elapsed += OnShowTimerElapsed;

            _hideTimer = new Timer();
            _hideTimer.AutoReset = true;
            _hideTimer.Elapsed += OnHideTimerElapsed;

            // Windows styles and events.
            _window.WindowStyle = WindowStyle.None;
            _window.ResizeMode = ResizeMode.NoResize;
            _window.ShowInTaskbar = false;

            _window.Closed += OnClose;
            _window.MouseLeave += OnMouseLeave;

            _window.AllowDrop = true;
            _window.PreviewDragEnter += OnDragEnter;
            _window.DragLeave += OnDragLeave;

            Microsoft.Win32.SystemEvents.DisplaySettingsChanged += OnDisplaySettingsChanged;

            // Default Values.
            PopupDelay = AppBarDefaultValues.PopupDelay;
            AutoHideDelay = AppBarDefaultValues.AutoHideDelay;
            ReserveScreen = AppBarDefaultValues.ReserveScreen;
            Docked = new DockPosition(AppBarDefaultValues.Docked);
            ActiveScreen = AppBarDefaultValues.Screen;        
        }        
Пример #2
0
        internal static Position FromNative(ref RECT rect)
        {
            Position position = new Position()
            {
                Top = rect.top,
                Bottom = rect.bottom,
                Left = rect.left,
                Right = rect.right
            };
            position.Height = position.Bottom - position.Top;
            position.Width = position.Right - position.Left;

            return position;
        }
        /// <summary>
        /// <para>
        ///     Sets the size and screen position of an appbar. The message specifies a 
        ///     screen edge and the bounding rectangle for the appbar. 
        /// </para>
        /// <para>
        ///     The system may adjust the bounding rectangle so that the appbar does not 
        ///     interfere with the Windows taskbar or any other appbars.
        /// </para>
        /// </summary>
        public void SetPosition(ref Position position, DockPosition dock)
        {
            APPBARDATA msgData = new APPBARDATA();
            msgData.cbSize = Marshal.SizeOf(msgData);
            msgData.hWnd = _handle;
            msgData.uEdge = (uint)dock.ToNative();
            position.ToNative(ref msgData.rc);

            Win32AppBar.SHAppBarMessage(ABM.ABM_SETPOS, ref msgData);
            position = Position.FromNative(ref msgData.rc);
        }
Пример #4
0
        void SlideInMinimize(DockPosition dockPosition, ActionQueueCallback completeCallback)
        {
            Log.DebugFormat("SlideInMinimize {0}", dockPosition);

            //ClearAnimations();

            DoubleAnimation widthAnimation, heightAnimation, leftAnimation, topAnimation;
            Position position = CalculateSlideInPosition(dockPosition);

            // No point doing the sliding animation when the size of the window hasn't actually changed.
            if (!HasPositionChanged(position))
            {
                Log.Debug("Window size has not changed significantly, cancelling sliding animation");
                completeCallback();
                return;
            }

            Storyboard storyBoard = new Storyboard();
            storyBoard.Duration = SlideDuration;
            storyBoard.Completed += (sender, e) =>
            {
                Position minimizedPosition = new Position();
                _appbar.Resize(ref minimizedPosition);

                DispatcherHelper.UIDispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
                    {
                        Left = position.Left;
                        Top = position.Top;
                        Width = position.Width;
                        Height = position.Height;

                        Log.DebugFormat("SlideInMinimize Finished, MainGrid {0}", GetMainGridPosition());
                        completeCallback();
                    }));
            };

            switch (dockPosition.Selected)
            {
                case DockEdge.Left:
                    widthAnimation = CreateGridDoubleAnimation(Grid.WidthProperty);
                    widthAnimation.To = 0;
                    storyBoard.Children.Add(widthAnimation);
                    break;
                case DockEdge.Right:
                    widthAnimation = CreateGridDoubleAnimation(Grid.WidthProperty);
                    widthAnimation.To = 0;
                    storyBoard.Children.Add(widthAnimation);

                    leftAnimation = CreateGridDoubleAnimation(Canvas.LeftProperty);
                    leftAnimation.To = position.Width;
                    storyBoard.Children.Add(leftAnimation);
                    break;
                case DockEdge.Top:
                    heightAnimation = CreateGridDoubleAnimation(Grid.HeightProperty);
                    heightAnimation.To = 0;
                    storyBoard.Children.Add(heightAnimation);
                    break;
                case DockEdge.Bottom:
                    heightAnimation = CreateGridDoubleAnimation(Grid.HeightProperty);
                    heightAnimation.To = 0;
                    storyBoard.Children.Add(heightAnimation);

                    topAnimation = CreateGridDoubleAnimation(Canvas.TopProperty);
                    heightAnimation.To = position.Height;
                    storyBoard.Children.Add(topAnimation);
                    break;
            }

            storyBoard.Freeze();
            storyBoard.Begin(_mainGrid);
        }
Пример #5
0
        void MinimizeWindow(object parameter)
        {
            DispatcherHelper.CheckBeginInvokeOnUI(() =>
                {
                    Log.DebugFormat("MinimizeWindow, {0}", DockPosition);

                    ClearAnimations();

                    Position position = new Position();
                    switch (DockPosition.Selected)
                    {
                        case DockEdge.Left:
                            position.Top = ActiveScreen.Bounds.Top;
                            position.Left = ActiveScreen.Bounds.Left;
                            position.Width = 1;
                            position.Height = ActiveScreen.Bounds.Height;
                            break;
                        case DockEdge.Right:
                            position.Top = ActiveScreen.Bounds.Top;
                            position.Left = ActiveScreen.Bounds.Right;
                            position.Width = 0;
                            position.Height = ActiveScreen.Bounds.Height;
                            break;
                        case DockEdge.Top:
                            position.Top = ActiveScreen.Bounds.Top;
                            position.Left = ActiveScreen.Bounds.Left;
                            position.Width = ActiveScreen.Bounds.Width;
                            position.Height = 0;
                            break;
                        case DockEdge.Bottom:
                            position.Top = ActiveScreen.Bounds.Bottom;
                            position.Left = ActiveScreen.Bounds.Left;
                            position.Width = ActiveScreen.Bounds.Width;
                            position.Height = 0;
                            break;
                    }
                    position.Bottom = position.Top + position.Height;
                    position.Right = position.Left + position.Width;

                    _appbar.CorrectPosition(ref position);

                    Log.DebugFormat("MinimizeWindow position {0}", position);

                    _mainGrid.Width = 0;
                    _mainGrid.Height = 0;
                    Width = 0;
                    Height = 0;

                    Left = position.Left;
                    Top = position.Top;
                    Width = position.Width;
                    Height = position.Height;

                    switch (DockPosition.Selected)
                    {
                        case DockEdge.Left:
                            Canvas.SetLeft(_mainGrid, 0);
                            Canvas.SetTop(_mainGrid, 0);
                            break;
                        case DockEdge.Right:
                            Canvas.SetLeft(_mainGrid, 0);
                            Canvas.SetTop(_mainGrid, 0);
                            break;
                        case DockEdge.Top:
                            Canvas.SetLeft(_mainGrid, 0);
                            Canvas.SetTop(_mainGrid, 0);
                            break;
                        case DockEdge.Bottom:
                            Canvas.SetLeft(_mainGrid, 0);
                            Canvas.SetTop(_mainGrid, 0);
                            break;
                    }

                    _mainGrid.Width = position.Width;
                    _mainGrid.Height = position.Height;

                    SwitchOrientation();

                    Log.DebugFormat("MinimzedWindow, MainGrid {0}", GetMainGridPosition());
                });
        }
Пример #6
0
        bool HasPositionChanged(Position position)
        {
            if (GetDifferenceBetween(position.Width, Width) < 10 &&
                GetDifferenceBetween(position.Height, Height) < 10 &&
                GetDifferenceBetween(position.Top, Top) < 10 &&
                GetDifferenceBetween(position.Left, Left) < 10)
            {
                return false;
            }

            return true;
        }
Пример #7
0
        Position CalculateSlideOutPosition(DockPosition dockPosition)
        {
            double windowSize = CalculateWindowWidth(IconRows);
            var bounds = ActiveScreen.Bounds;
            //var bounds = ActiveScreen.WorkingArea;

            /*
            int x;
            int y;
            WpfHelper.TransformToPixels(this, System.Windows.SystemParameters.WorkArea.X, System.Windows.SystemParameters.WorkArea.Y, out x, out y);
            var bounds = new Rect(x, y, System.Windows.SystemParameters.WorkArea.Width,System.Windows.SystemParameters.WorkArea.Height);
            Log.DebugFormat("CalculateSlieOut WPF bounds {0}", bounds);
             */

            Position position = new Position();
            switch (dockPosition.Selected)
            {
                case DockEdge.Left:
                    position.Top = bounds.Top;
                    position.Left = bounds.Left;
                    position.Width = windowSize;
                    position.Height = bounds.Height;
                    break;
                case DockEdge.Right:
                    position.Top = bounds.Top;
                    position.Left = bounds.Right - windowSize;
                    position.Width = windowSize;
                    position.Height = bounds.Height;
                    break;
                case DockEdge.Top:
                    position.Top = bounds.Top;
                    position.Left = bounds.Left;
                    position.Width = bounds.Width;
                    position.Height = VerticallyDockedHeight;
                    break;
                case DockEdge.Bottom:
                    position.Top = bounds.Bottom - VerticallyDockedHeight;
                    position.Left = bounds.Left;
                    position.Width = bounds.Width;
                    position.Height = VerticallyDockedHeight;
                    break;
            }
            position.Bottom = position.Top + position.Height;
            position.Right = position.Left + position.Width;

            _appbar.CorrectPosition(ref position);

            Log.DebugFormat("SlideOut position {0}", position);
            return position;
        }
Пример #8
0
        Position CalculateSlideInPosition(DockPosition dockPosition)
        {
            Position position = new Position();
            switch (dockPosition.Selected)
            {
                case DockEdge.Left:
                    position.Top = this.Top;
                    position.Left = ActiveScreen.Bounds.Left - this.ActualWidth;
                    position.Width = this.ActualWidth;
                    position.Height = this.ActualHeight;
                    break;
                case DockEdge.Right:
                    position.Top = this.Top;
                    position.Left = ActiveScreen.Bounds.Right + this.ActualWidth;
                    position.Width = this.ActualWidth;
                    position.Height = ActiveScreen.Bounds.Height;
                    break;
                case DockEdge.Top:
                    position.Top = ActiveScreen.Bounds.Top - this.ActualHeight;
                    position.Left = this.Left;
                    position.Width = this.ActualHeight;
                    position.Height = this.ActualHeight;
                    break;
                case DockEdge.Bottom:
                    position.Top = ActiveScreen.Bounds.Bottom + this.ActualHeight;
                    position.Left = this.Left;
                    position.Width = this.ActualWidth;
                    position.Height = this.ActualHeight;;
                    break;
            }
            position.Bottom = position.Top + position.Height;
            position.Right = position.Left + position.Width;

            _appbar.CorrectPosition(ref position);

            Log.DebugFormat("SlideInMinimize position {0}", position);
            return position;
        }
Пример #9
0
        void SetMinimized()
        {
            if (_toolbar == null)
                return;

            Position position = new Position();
            _toolbar.SetPosition(ref position, DockPosition.Left());
        }
Пример #10
0
 public void Resize(ref Position position)
 {
     _currentPosition = position;
     if (ReserveScreen)
         SetNormal();
     else
         SetMinimized();
 }
Пример #11
0
        public void CorrectPosition(ref Position position)
        {
            if (_toolbar != null)
            {
                _toolbar.QueryPosition(ref position, Docked);

                // The query position call will sometimes set the height or width 
                // to a negative value if the app bar is moved to the same side as the taskbar.

                // Obviously that's going to cause problems so set them to 0 in that situation.
                if (position.Height < 0)
                    position.Height = 0;
                if (position.Width < 0)
                    position.Width = 0;

                _currentPosition = position;
            }
        }
Пример #12
0
 public void SetPosition(ref Position position, DockPosition dock)
 {
     Dock(dock);
     CorrectPosition(ref position);
     Resize(ref position);           
 }