using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Primitives; using Avalonia.Styling; using LibationFileManager; using System; using System.Threading.Tasks; namespace LibationAvalonia.Dialogs { public abstract class DialogWindow : Window { public bool SaveAndRestorePosition { get; set; } = true; public Control ControlToFocusOnShow { get; set; } protected override Type StyleKeyOverride => typeof(DialogWindow); public static readonly StyledProperty UseCustomTitleBarProperty = AvaloniaProperty.Register(nameof(UseCustomTitleBar)); public bool UseCustomTitleBar { get { return GetValue(UseCustomTitleBarProperty); } set { SetValue(UseCustomTitleBarProperty, value); } } public DialogWindow() { KeyDown += DialogWindow_KeyDown; Initialized += DialogWindow_Initialized; Opened += DialogWindow_Opened; Closing += DialogWindow_Closing; UseCustomTitleBar = Configuration.IsWindows; if (Design.IsDesignMode) RequestedThemeVariant = ThemeVariant.Dark; } private bool fixedMinHeight = false; private bool fixedMaxHeight = false; private bool fixedHeight = false; protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) { const int customTitleBarHeight = 30; if (UseCustomTitleBar) { if (change.Property == MinHeightProperty && !fixedMinHeight) { fixedMinHeight = true; MinHeight += customTitleBarHeight; fixedMinHeight = false; } if (change.Property == MaxHeightProperty && !fixedMaxHeight) { fixedMaxHeight = true; MaxHeight += customTitleBarHeight; fixedMaxHeight = false; } if (change.Property == HeightProperty && !fixedHeight) { fixedHeight = true; Height += customTitleBarHeight; fixedHeight = false; } } base.OnPropertyChanged(change); } public DialogWindow(bool saveAndRestorePosition) : this() { SaveAndRestorePosition = saveAndRestorePosition; } protected override void OnApplyTemplate(TemplateAppliedEventArgs e) { base.OnApplyTemplate(e); if (!UseCustomTitleBar) return; var closeButton = e.NameScope.Find