WPF下Window设置WindowStyle="None"时实现鼠标拖动移动窗口位置

在WPF下当Window设置WindowStyle="None"时,默认的鼠标拖动窗口位置无效,需要自己定义代码实现,具体做法如下:

1、在xaml中引入MouseMove事件

<Window x:Class="Gvitech.Application.WPF.UI.FunFacility.WindowEquipmentRecord"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="WindowEquipmentRecord" Height="360" Width="680" WindowStyle="None"  
        WindowState="Normal" AllowsTransparency="True" MouseMove="window_MouseMove" >

2、在代码中实现MouseMove代码 

private void window_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                this.DragMove();
            }
        }



猜你喜欢

转载自blog.csdn.net/mpegfour/article/details/78878742