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

来源:互联网 发布:php socket可以做什么 编辑:程序博客网 时间:2024/06/05 01:10
在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();            }        }



阅读全文
0 0
原创粉丝点击