自定义窗体标题栏及尺寸调整手柄完成
This commit is contained in:
54
MVVMExample/Helper.cs
Normal file
54
MVVMExample/Helper.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MVVMExample
|
||||
{
|
||||
public static partial class Helper
|
||||
{
|
||||
/// <summary>
|
||||
/// 绑定自定义窗口标题栏与尺寸调整句柄
|
||||
/// </summary>
|
||||
/// <param name="window">要进行绑定的窗口</param>
|
||||
/// <param name="handle">窗口位置拖动句柄</param>
|
||||
/// <param name="slider">窗口尺寸调整句柄</param>
|
||||
/// <param name="maxBut">最大化按钮</param>
|
||||
/// <param name="minBut">最小化按钮</param>
|
||||
/// <param name="closeBut">关闭按钮</param>
|
||||
public static void BindWindowEdge(this Window window, InputElement? handle = null, InputElement? slider = null, Button? maxBut = null, Button? minBut = null, Button? closeBut = null)
|
||||
{
|
||||
// 隐藏窗口默认标题栏与尺寸调整句柄
|
||||
window.SystemDecorations = SystemDecorations.None;
|
||||
|
||||
if (handle != null)
|
||||
handle.PointerPressed += (s, e) =>
|
||||
{
|
||||
if (e.GetCurrentPoint(window).Properties.IsLeftButtonPressed) window.BeginMoveDrag(e); // 关键:开始窗口拖拽
|
||||
};
|
||||
if (slider != null)
|
||||
slider.PointerPressed += (s, e) =>
|
||||
{
|
||||
if (e.GetCurrentPoint(window).Properties.IsLeftButtonPressed) window.BeginResizeDrag(WindowEdge.SouthEast, e);
|
||||
};
|
||||
if (maxBut != null)
|
||||
maxBut.Click += (s, e) =>
|
||||
{
|
||||
window.WindowState = window.WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
|
||||
};
|
||||
if (minBut != null)
|
||||
minBut.Click += (s, e) =>
|
||||
{
|
||||
window.WindowState = WindowState.Minimized;
|
||||
};
|
||||
if (closeBut != null)
|
||||
closeBut.Click += (s, e) =>
|
||||
{
|
||||
window.Close();
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user