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

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

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

WPF 自定义的窗口拖动
    


            
WPF 自定义的窗口拖动
        private void UIElement_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (e.ButtonState==MouseButtonState.Pressed)
            {
                this.DragMove();
            }
        }
WPF 自定义的窗口拖动
    


            
WPF 自定义的窗口拖动

 

授之以鱼,仅供一饭之需; 授之以渔,则一生受用. 莫要单纯复制粘贴

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

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

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

WPF 自定义的窗口拖动
    


            
WPF 自定义的窗口拖动
        private void UIElement_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (e.ButtonState==MouseButtonState.Pressed)
            {
                this.DragMove();
            }
        }
WPF 自定义的窗口拖动
    


            
WPF 自定义的窗口拖动

 

相关文章:

  • 2021-12-22
  • 2021-05-27
  • 2022-01-19
  • 2022-12-23
  • 2022-03-01
  • 2022-12-23
  • 2022-12-23
  • 2021-05-30
猜你喜欢
  • 2021-11-22
  • 2022-12-23
  • 2022-12-23
  • 2022-02-02
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案