WPF 自定义的窗口拖动

时间:2021-04-27 09:01:50

WPF原有的窗口样式太丑,当我们重新定义窗口时,则需要添加一些额外的功能,如拖动~

1、在界面上对布局元素如Grid,添加委托事件: MouseLeftButtonDown="UIElement_OnMouseLeftButtonDown"

2、委托方法中处理一下就行了:

        private void UIElement_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (e.ButtonState==MouseButtonState.Pressed)
            {
                this.DragMove();
            }
        }