拖动一个无边框窗口
代码
DragBorderlessWindowSample.xaml
<Window
x:Class="Drag_a_Borderless_Window_Sample.DragBorderlessWindowSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="DragBorderlessWindowSample"
Width="800"
Height="450"
AllowsTransparency="True"
Background="Gray"
MouseLeftButtonDown="Window_MouseLeftButtonDown"
WindowStyle="None"
mc:Ignorable="d">
<Grid>
<Button
Name="btnClose"
Width="75"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Click="BtnClose_OnClick"
Content="Close" />
</Grid>
</Window>
DragBorderlessWindowSample.xaml
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.DragMove();
}
private void BtnClose_OnClick(object sender, RoutedEventArgs e)
{
Close();
}
效果