wpf异形窗口,用DragMove()实现了标题栏拖动,并且拖到桌面顶端能自动最大化,然后就不能拖回来了,必须退出最大化才能拖动,这个怎么解决掉?用windowProc截获WM_NCHITTEST,返回HITCAPTION倒是没这问题,但是根据鼠标位置判断的话,标题栏区域的一堆按钮被遮住了,分别判断不方便通用和修改。

解决方案 »

  1.   

    DragMove 最大化后是不允许拖动的,解决办法在最大化WindowState改为Normal,并设置窗口大小和位置Private Sub MouseLefDown(ByVal sender as Object, ByVal e as System.Windows.Input.MouseButtonEventArgs)
    'TODO: Add event handler implementation here.
    If e.LeftButton =System.Windows.Input.MouseButtonState.Pressed Then
                If Me.WindowState = WindowState.Maximized Then
                    Me.WindowState = WindowState.Normal
                    Me.Width = SystemParameters.WorkArea.Width
                    Me.Height = SystemParameters.WorkArea.Height
                    Window.Left = 0
                    Window.Top = 0
                    WindowStartupLocation = Windows.WindowStartupLocation.Manual            End If
    Me.DragMove 
         End If 
    End Sub
      

  2.   

    我试了下尺寸大小不要修改了

    Private Sub MouseLefDown(ByVal sender as Object, ByVal e as System.Windows.Input.MouseButtonEventArgs)
    'TODO: Add event handler implementation here.
    If e.LeftButton =System.Windows.Input.MouseButtonState.Pressed Then
                If Me.WindowState = WindowState.Maximized Then
                    Me.WindowState = WindowState.Normal
                    Window.Left = 0
                    Window.Top = 0
                    WindowStartupLocation = Windows.WindowStartupLocation.Manual
                End If
    Me.DragMove 
         End If 
    End Sub
      

  3.   

    C#代码如下:private void MouseLefDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
    {
    //TODO: Add event handler implementation here.
    if (e.LeftButton == System.Windows.Input.MouseButtonState.Pressed) {
    if (this.WindowState == WindowState.Maximized) {
    this.WindowState = WindowState.Normal;
    Window.Left = 0;
    Window.Top = 0;
    WindowStartupLocation = System.Windows.WindowStartupLocation.Manual;
    }
    this.DragMove();
    }
    }