diff --git a/MVVMExample/Helper.cs b/MVVMExample/Helper.cs new file mode 100644 index 0000000..8a01381 --- /dev/null +++ b/MVVMExample/Helper.cs @@ -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 + { + /// + /// 绑定自定义窗口标题栏与尺寸调整句柄 + /// + /// 要进行绑定的窗口 + /// 窗口位置拖动句柄 + /// 窗口尺寸调整句柄 + /// 最大化按钮 + /// 最小化按钮 + /// 关闭按钮 + 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(); + }; + } + } +} diff --git a/MVVMExample/Themes/DefaultStyles.axaml b/MVVMExample/Themes/DefaultStyles.axaml new file mode 100644 index 0000000..a723879 --- /dev/null +++ b/MVVMExample/Themes/DefaultStyles.axaml @@ -0,0 +1,16 @@ + + + + + + + + + + + diff --git a/MVVMExample/Views/MainWindow.axaml b/MVVMExample/Views/MainWindow.axaml index b955207..e2074de 100644 --- a/MVVMExample/Views/MainWindow.axaml +++ b/MVVMExample/Views/MainWindow.axaml @@ -1,4 +1,4 @@ - - + Title="MVVMExample" + CanResize="True"> + + + - - - - + + + + + + + + + + + +