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">
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/MVVMExample/Views/MainWindow.axaml.cs b/MVVMExample/Views/MainWindow.axaml.cs
index 31a9369..407be3e 100644
--- a/MVVMExample/Views/MainWindow.axaml.cs
+++ b/MVVMExample/Views/MainWindow.axaml.cs
@@ -1,4 +1,6 @@
-using Avalonia.Controls;
+using Avalonia.Controls;
+using Avalonia.Input;
+using Avalonia.Interactivity;
namespace MVVMExample.Views
{
@@ -7,6 +9,43 @@ namespace MVVMExample.Views
public MainWindow()
{
InitializeComponent();
+ //
+ }
+ // 处理标题栏拖拽以实现窗口移动
+ private void TitleBar_PointerPressed(object? sender, PointerPressedEventArgs e)
+ {
+ if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
+ {
+ BeginMoveDrag(e); // 关键:开始窗口拖拽
+ }
+ }
+ private void Bar_PointerPressed(object? sender, PointerPressedEventArgs e)
+ {
+ if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
+ {
+ BeginResizeDrag(WindowEdge.SouthEast, e); // 关键:开始窗口拖拽
+ }
+ }
+ // 最小化按钮
+ private void MinimizeBtn_Click(object? sender, RoutedEventArgs e)
+ {
+ WindowState = WindowState.Minimized;
+ }
+
+ // 最大化/还原按钮
+ private void MaximizeBtn_Click(object? sender, RoutedEventArgs e)
+ {
+ WindowState = WindowState == WindowState.Maximized
+ ? WindowState.Normal
+ : WindowState.Maximized;
+ // 可选:切换最大化/还原按钮的图标
+ MaximizeBtn.Content = WindowState == WindowState.Maximized ? "❐" : "□";
+ }
+
+ // 关闭按钮
+ private void CloseBtn_Click(object? sender, RoutedEventArgs e)
+ {
+ Close();
}
}
}
\ No newline at end of file