using Avalonia.Controls; using Avalonia.Input; using Avalonia.Interactivity; namespace DodoSSH.Client.App.Views; /// Settings mode's own titlebar — see the remark in the markup for why it is not TitleBar itself. internal sealed partial class SettingsTitleBar : UserControl { public SettingsTitleBar() => InitializeComponent(); private Window? Host => TopLevel.GetTopLevel(this) as Window; /// Left button only, and only on a press nothing inside the bar has already handled. private void OnDrag(object? sender, PointerPressedEventArgs e) { if (e.Handled || !e.GetCurrentPoint(this).Properties.IsLeftButtonPressed) { return; } Host?.BeginMoveDrag(e); } private void OnMinimise(object? sender, RoutedEventArgs e) { if (Host is { } window) { window.WindowState = WindowState.Minimized; } } /// Both the button and a double-click on the bar arrive here, as Windows convention expects. private void OnToggleMaximised(object? sender, RoutedEventArgs e) { if (Host is not { } window) { return; } window.WindowState = window.WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized; } private void OnClose(object? sender, RoutedEventArgs e) => Host?.Close(); }