自定义窗体标题栏及尺寸调整手柄完成
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user