Metro window resizes with single click on the title bar if a pop up is open

Dec 11, 2012 at 7:26 PM
Edited Dec 11, 2012 at 7:28 PM

When the metro window is maximized, pop up a dropdown button, menu or context, and with the popup open, mouse left click on the title bar will make the window resize at a new position. I have a fix for this in \Fluent\MetroWindow.cs.

See the bold text below:

              

        bool _isContextMenuOpen = false;  
        bool _isMouseDown = false;
        protected void TitleBarMouseDown(object sender, MouseButtonEventArgs e)
        {
          if (e.RightButton != MouseButtonState.Pressed && e.MiddleButton != MouseButtonState.Pressed && e.LeftButton == MouseButtonState.Pressed)
          {
            DragMove();

            // Do not resize window 
            _isMouseDown = (e.ClickCount == 1 ? true : false);            
          }

            if (e.ClickCount == 2 && (ResizeMode == ResizeMode.CanResizeWithGrip || ResizeMode == ResizeMode.CanResize))
            {
                WindowState = WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
            }
        }
        protected override void OnContextMenuOpening(ContextMenuEventArgs e)
        {
          // Do not resize window 
          _isContextMenuOpen = true;
          base.OnContextMenuOpening(e);
        }

        protected override void OnContextMenuClosing(ContextMenuEventArgs e)
        {
          // Do not resize window 
          _isContextMenuOpen = false;
          base.OnContextMenuClosing(e);
        }
        protected void TitleBarMouseUp(object sender, MouseButtonEventArgs e)
        {
            if (!ShowIconOnTitleBar) return;

            _isMouseDown = false;

            var mousePosition = GetCorrectPosition(this);

            if (mousePosition.X <= TitlebarHeight && mousePosition.Y <= TitlebarHeight)
            {
                if ((DateTime.Now - lastMouseClick).TotalMilliseconds <= doubleclick)
                {
                    Close();
                    return;
                }
                lastMouseClick = DateTime.Now;

                ShowSystemMenuPhysicalCoordinates(this, PointToScreen(new Point(0, TitlebarHeight)));
            }
            else if (e.ChangedButton == MouseButton.Right)
            {
                ShowSystemMenuPhysicalCoordinates(this, PointToScreen(GetCorrectPosition(this)));
            }
        }

private void TitleBarMouseMove(object sender, MouseEventArgs e)
        {
                      if (e.RightButton != MouseButtonState.Pressed && e.MiddleButton != MouseButtonState.Pressed
                && e.LeftButton == MouseButtonState.Pressed && WindowState == WindowState.Maximized
                && ResizeMode != ResizeMode.NoResize && _isMouseDown && !_isContextMenuOpen)
            {
                // Calculating correct left coordinate for multi-screen system.
                Point mouseAbsolute = PointToScreen(Mouse.GetPosition(this));
                double width = RestoreBounds.Width;
                double left = mouseAbsolute.X - width / 2;

                // Aligning window's position to fit the screen.
                double virtualScreenWidth = SystemParameters.VirtualScreenWidth;
                left = left + width > virtualScreenWidth ? virtualScreenWidth - width : left;

                var mousePosition = e.MouseDevice.GetPosition(this);

                // When dragging the window down at the very top of the border,
                // move the window a bit upwards to avoid showing the resize handle as soon as the mouse button is released
                Top = mousePosition.Y < 5 ? -5 : mouseAbsolute.Y - mousePosition.Y;
                Left = left;

                // Restore window to normal state.
                WindowState = WindowState.Normal;

                DragMove();
            }
        }

 

Dec 12, 2012 at 1:14 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.