using System.ComponentModel; using Avalonia; using Avalonia.Controls; namespace Ursa.Controls; /// /// Ursa Window is an advanced Window control that provides a lot of features and customization options. /// public class UrsaWindow: Window { protected override Type StyleKeyOverride => typeof(UrsaWindow); public static readonly StyledProperty IsFullScreenButtonVisibleProperty = AvaloniaProperty.Register( nameof(IsFullScreenButtonVisible)); public bool IsFullScreenButtonVisible { get => GetValue(IsFullScreenButtonVisibleProperty); set => SetValue(IsFullScreenButtonVisibleProperty, value); } public static readonly StyledProperty IsMinimizeButtonVisibleProperty = AvaloniaProperty.Register( nameof(IsMinimizeButtonVisible), true); public bool IsMinimizeButtonVisible { get => GetValue(IsMinimizeButtonVisibleProperty); set => SetValue(IsMinimizeButtonVisibleProperty, value); } public static readonly StyledProperty IsRestoreButtonVisibleProperty = AvaloniaProperty.Register( nameof(IsRestoreButtonVisible), true); public bool IsRestoreButtonVisible { get => GetValue(IsRestoreButtonVisibleProperty); set => SetValue(IsRestoreButtonVisibleProperty, value); } public static readonly StyledProperty IsCloseButtonVisibleProperty = AvaloniaProperty.Register( nameof(IsCloseButtonVisible), true); public bool IsCloseButtonVisible { get => GetValue(IsCloseButtonVisibleProperty); set => SetValue(IsCloseButtonVisibleProperty, value); } public static readonly StyledProperty IsTitleBarVisibleProperty = AvaloniaProperty.Register( nameof(IsTitleBarVisible), true); public bool IsTitleBarVisible { get => GetValue(IsTitleBarVisibleProperty); set => SetValue(IsTitleBarVisibleProperty, value); } public static readonly StyledProperty IsManagedResizerVisibleProperty = AvaloniaProperty.Register( nameof(IsManagedResizerVisible)); public bool IsManagedResizerVisible { get => GetValue(IsManagedResizerVisibleProperty); set => SetValue(IsManagedResizerVisibleProperty, value); } public static readonly StyledProperty TitleBarContentProperty = AvaloniaProperty.Register( nameof(TitleBarContent)); public object? TitleBarContent { get => GetValue(TitleBarContentProperty); set => SetValue(TitleBarContentProperty, value); } public static readonly StyledProperty LeftContentProperty = AvaloniaProperty.Register( nameof(LeftContent)); public object? LeftContent { get => GetValue(LeftContentProperty); set => SetValue(LeftContentProperty, value); } public static readonly StyledProperty RightContentProperty = AvaloniaProperty.Register( nameof(RightContent)); public object? RightContent { get => GetValue(RightContentProperty); set => SetValue(RightContentProperty, value); } public static readonly StyledProperty TitleBarMarginProperty = AvaloniaProperty.Register( nameof(TitleBarMargin)); public Thickness TitleBarMargin { get => GetValue(TitleBarMarginProperty); set => SetValue(TitleBarMarginProperty, value); } protected virtual async Task CanClose() { return await Task.FromResult(true); } private bool _canClose = false; protected override async void OnClosing(WindowClosingEventArgs e) { VerifyAccess(); if (!_canClose) { e.Cancel = true; _canClose = await CanClose(); if (_canClose) { Close(); } } base.OnClosing(e); } }