添加项目文件。
This commit is contained in:
41
UIShare/Helpers/WindowDragHelper.cs
Normal file
41
UIShare/Helpers/WindowDragHelper.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace UIShare.Helpers
|
||||
{
|
||||
public static class WindowDragHelper
|
||||
{
|
||||
public static readonly DependencyProperty EnableWindowDragProperty =
|
||||
DependencyProperty.RegisterAttached(
|
||||
"EnableWindowDrag",
|
||||
typeof(bool),
|
||||
typeof(WindowDragHelper),
|
||||
new PropertyMetadata(false, OnEnableWindowDragChanged));
|
||||
|
||||
public static bool GetEnableWindowDrag(DependencyObject obj) =>
|
||||
(bool)obj.GetValue(EnableWindowDragProperty);
|
||||
|
||||
public static void SetEnableWindowDrag(DependencyObject obj, bool value) =>
|
||||
obj.SetValue(EnableWindowDragProperty, value);
|
||||
|
||||
private static void OnEnableWindowDragChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (d is FrameworkElement element)
|
||||
{
|
||||
if ((bool)e.NewValue)
|
||||
element.MouseLeftButtonDown += Element_MouseLeftButtonDown;
|
||||
else
|
||||
element.MouseLeftButtonDown -= Element_MouseLeftButtonDown;
|
||||
}
|
||||
}
|
||||
|
||||
private static void Element_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (sender is FrameworkElement element)
|
||||
{
|
||||
var window = Window.GetWindow(element);
|
||||
window?.DragMove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user