benruehl / adonis-ui

Lightweight UI toolkit for WPF applications offering classic but enhanced windows visuals
https://benruehl.github.io/adonis-ui/
MIT License
1.7k stars 143 forks source link

Wrong window position after minimizing with double click #131

Closed Tyreens closed 3 years ago

Tyreens commented 3 years ago

Hi,

there is a bug when you minimizing the "AdonisWindow" with a double click on the titlebar. The window will jump to the mouse cursor after minimizing when you enter the title bar of the window with your mouse.

To Reproduce Steps to reproduce the behavior:

  1. Open any AdonisWindow
  2. Double click on title bar to maximize
  3. Double click on title bar to minimize
  4. Move mouse over title bar (do not drag, just hover)

Expected behavior Window does not change the position after minimizing followed by moving the mouse over the title bar.

Tyreens commented 3 years ago

This should solve it:

protected virtual void InitDragMoveThumb(FrameworkElement dragMoveThumb)
        {
            dragMoveThumb.MouseLeftButtonDown += (s, e) =>
            {
                if (e.ChangedButton == MouseButton.Left && e.ClickCount == 1)
                {
                    if (WindowState == WindowState.Maximized)
                        dragMoveThumb.MouseMove += RestoreOnMouseMove;

                    if (Mouse.LeftButton == MouseButtonState.Pressed)
                        DragMove();
                }

                if (e.ClickCount == 2 &&
                    (ResizeMode == ResizeMode.CanResize || ResizeMode == ResizeMode.CanResizeWithGrip))
                {
                    ToggleWindowState();
                }
            };

            dragMoveThumb.MouseLeftButtonUp += (s, e) => dragMoveThumb.MouseMove -= RestoreOnMouseMove;

            dragMoveThumb.MouseRightButtonUp += (s, e) => OpenSystemContextMenu(e.GetPosition(this));
        }
benruehl commented 3 years ago

Yes, that seems to behave a little incorrect. Thanks for reporting!

oriash93 commented 3 years ago

@benruehl Can I make a PR?

benruehl commented 3 years ago

@oriash93 Yes of course, please go ahead :)