Files
AvaloniaExample/MVVMExample/Views/MainWindow.axaml.cs

51 lines
1.6 KiB
C#

using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
namespace MVVMExample.Views
{
public partial class MainWindow : Window
{
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();
}
}
}