当窗口最大化模式时,如何移动(拖放)wpf窗口。我正在使用下面的代码,但是当窗口是最大化模式时,它就不起作用了。
private void Window_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
this.DragMove();
}
}
如何解决这个问题?
答案 0 :(得分:0)
使用PreviewMouseLeftButtonDown事件,通过代码将WindowState更改为Normal,然后应用DragMove方法。
private void Grid_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (WindowState == WindowState.Maximized)
{
WindowState = WindowState.Normal;
}
DragMove();
}
答案 1 :(得分:0)
订阅鼠标移动evet时,您可以更改窗口输入代码heresize和location。例如
`if (this.WindowState == WindowState.Maximized)
{
this.Width = this.ActualWidth;
this.Height = this.ActualHeight;
this.Left = 0;
this.Top = 0;
this.WindowStartupLocation = WindowStartupLocation.Manual;
this.WindowState = WindowState.Normal;
}`