Make WPF window draggable, no matter what element is clicked

前端 未结 9 1014
灰色年华
灰色年华 2020-12-04 07:47

My question is 2 fold, and I am hoping there are easier solutions to both provided by WPF rather than the standard solutions from WinForms (which Christophe

9条回答
  •  -上瘾入骨i
    2020-12-04 08:32

    This is all needed!

    private void UiElement_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                if (this.WindowState == WindowState.Maximized) // In maximum window state case, window will return normal state and continue moving follow cursor
                {
                    this.WindowState = WindowState.Normal;
                    Application.Current.MainWindow.Top = 3;// 3 or any where you want to set window location affter return from maximum state
                }
                this.DragMove();
            }
        }
    

提交回复
热议问题