案例實現效果:通過鼠標左鍵單擊窗口空白處,按住鼠標來拖動窗口。該案例實現很簡單,可以應用在一些自定義窗口(如窗口不顯示標題欄等情況)。
<Window x:Class="ClickWhitespaceAndDrag.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="ClickWhitespaceAndDrag" Height="300" Width="300" MouseLeftButtonDown="MyMouseLeftButtonDown"
>
<Grid>
</Grid>
</Window>
void MyMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.DragMove();
}