WPF的窗体设置WindowStyle=none时,如何移动窗体

1. 在WPF中当将主窗体的WindowStyle设置为none时,使用鼠标移动不了窗体

2. 解决方法:

   2.1. 在Windows的Load方法中增加一下代码:

private void Window_Loaded(object sender, RoutedEventArgs e)
{
       this.MouseDown += delegate { DragMove(); };
}

 2.2. 重写主窗体的 OnMouseLefButtonDown()方法:

protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
 {
            base.OnMouseLeftButtonDown(e);

            // Begin dragging the window
            this.DragMove();
 }

  参考:http://stackoverflow.com/questions/1761854/cant-drag-and-move-a-wpf-form

posted @ 2015-06-30 15:11  一菲聪天  阅读(2502)  评论(2编辑  收藏  举报