简体   繁体   English

实施窗口拖放WPF

[英]Implement Window Drag and Drop WPF

I had to create a new Window from scratch using MahApps.Metro like this . 我必须像这样使用MahApps.Metro从头开始创建一个新窗口。 This creates for you a borderlesss Window without the standard Window buttons (Close, Restore or Minimze). 这会为您创建一个没有标准窗口按钮(“关闭”,“还原”或“最小化”)的无边界窗口。

I implemented these buttons and it works pretty well. 我实现了这些按钮,效果很好。 The thing that I see that is not like all anothers windows is the behavior that allows the user to change the position of the window, using drag and drop. 我看到的与其他窗口不同的是,该行为允许用户使用拖放来更改窗口的位置。

I was looking for but I couldn't figure how to do it. 我一直在寻找,但我不知道该怎么做。

How should I implement the behavior of drag and drop in a non-standard window? 如何在非标准窗口中实现拖放行为?

Make your window handles the event MouseLeftButtonDown : 让您的窗口处理事件MouseLeftButtonDown

    private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        this.DragMove();
    }

This works on standard WPF applications, not sure if Metro apps can use this. 这适用于标准WPF应用程序,不确定Metro应用程序是否可以使用它。

If you prefer, you can handle this event using another control. 如果愿意,可以使用另一个控件来处理此事件。 For instance, you can handle it with an image control that simulates a title bar. 例如,您可以使用模拟标题栏的图像控件来处理它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM