2026-01-06 16:37:54 +08:00
|
|
|
|
using Avalonia.Controls;
|
|
|
|
|
|
using Avalonia.Input;
|
|
|
|
|
|
using Avalonia.Interactivity;
|
2026-01-06 14:52:23 +08:00
|
|
|
|
|
|
|
|
|
|
namespace MVVMExample.Views
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class MainWindow : Window
|
|
|
|
|
|
{
|
|
|
|
|
|
public MainWindow()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
2026-01-06 16:37:54 +08:00
|
|
|
|
//
|
|
|
|
|
|
}
|
|
|
|
|
|
// 处理标题栏拖拽以实现窗口移动
|
|
|
|
|
|
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();
|
2026-01-06 14:52:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|