diff --git a/src/Ursa.Themes.Semi/Controls/UrsaView.axaml b/src/Ursa.Themes.Semi/Controls/UrsaView.axaml index 3d1ddf9..6de59f8 100644 --- a/src/Ursa.Themes.Semi/Controls/UrsaView.axaml +++ b/src/Ursa.Themes.Semi/Controls/UrsaView.axaml @@ -38,7 +38,7 @@ IsVisible="{TemplateBinding IsTitleBarVisible}" Content="{TemplateBinding RightContent}" /> - + diff --git a/src/Ursa.Themes.Semi/Controls/UrsaWindow.axaml b/src/Ursa.Themes.Semi/Controls/UrsaWindow.axaml index 3614387..3ba0f96 100644 --- a/src/Ursa.Themes.Semi/Controls/UrsaWindow.axaml +++ b/src/Ursa.Themes.Semi/Controls/UrsaWindow.axaml @@ -74,7 +74,10 @@ RightContent="{Binding $parent[u:UrsaWindow].RightContent}" /> - + -/// Ursa window is designed to +/// Represents a custom content control with additional properties for managing a title bar and related content. +/// This control can be used as the top level container for platforms without windowing toplevel support. /// -public class UrsaView: ContentControl +public class UrsaView : ContentControl { + /// + /// The name of the dialog host part in the control template. + /// + public const string PART_DialogHost = "PART_DialogHost"; + + /// + /// Defines the visibility of the title bar. + /// public static readonly StyledProperty IsTitleBarVisibleProperty = UrsaWindow.IsTitleBarVisibleProperty.AddOwner(); + /// + /// Defines the content on the left side of the control. + /// + public static readonly StyledProperty LeftContentProperty = + UrsaWindow.LeftContentProperty.AddOwner(); + + /// + /// Defines the content on the right side of the control. + /// + public static readonly StyledProperty RightContentProperty = + UrsaWindow.RightContentProperty.AddOwner(); + + /// + /// Defines the content of the title bar. + /// + public static readonly StyledProperty TitleBarContentProperty = + UrsaWindow.TitleBarContentProperty.AddOwner(); + + /// + /// Defines the margin of the title bar. + /// + public static readonly StyledProperty TitleBarMarginProperty = + UrsaWindow.TitleBarMarginProperty.AddOwner(); + + /// + /// Gets or sets a value indicating whether the title bar is visible. + /// public bool IsTitleBarVisible { get => GetValue(IsTitleBarVisibleProperty); set => SetValue(IsTitleBarVisibleProperty, value); } - public static readonly StyledProperty LeftContentProperty = - UrsaWindow.LeftContentProperty.AddOwner(); - + /// + /// Gets or sets the content on the left side of the control. + /// public object? LeftContent { get => GetValue(LeftContentProperty); set => SetValue(LeftContentProperty, value); } - public static readonly StyledProperty RightContentProperty = - UrsaWindow.RightContentProperty.AddOwner(); - + /// + /// Gets or sets the content on the right side of the control. + /// public object? RightContent { get => GetValue(RightContentProperty); set => SetValue(RightContentProperty, value); } - public static readonly StyledProperty TitleBarContentProperty = - UrsaWindow.TitleBarContentProperty.AddOwner(); - + /// + /// Gets or sets the content of the title bar. + /// public object? TitleBarContent { get => GetValue(TitleBarContentProperty); set => SetValue(TitleBarContentProperty, value); } - public static readonly StyledProperty TitleBarMarginProperty = - UrsaWindow.TitleBarMarginProperty.AddOwner(); - + /// + /// Gets or sets the margin of the title bar. + /// public Thickness TitleBarMargin { get => GetValue(TitleBarMarginProperty); set => SetValue(TitleBarMarginProperty, value); } + + /// + /// Applies the control template and initializes the dialog host if present. + /// + /// The event arguments containing the template information. + protected override void OnApplyTemplate(TemplateAppliedEventArgs e) + { + base.OnApplyTemplate(e); + var host = e.NameScope.Find(PART_DialogHost); + if (host is not null) LogicalChildren.Add(host); + } } \ No newline at end of file diff --git a/src/Ursa/Windows/UrsaWindow.cs b/src/Ursa/Windows/UrsaWindow.cs index 92fd303..d951b7f 100644 --- a/src/Ursa/Windows/UrsaWindow.cs +++ b/src/Ursa/Windows/UrsaWindow.cs @@ -1,112 +1,205 @@ -using System.ComponentModel; using Avalonia; using Avalonia.Controls; +using Avalonia.Controls.Primitives; namespace Ursa.Controls; /// -/// Ursa Window is an advanced Window control that provides a lot of features and customization options. +/// Ursa Window is an advanced Window control that provides a lot of features and customization options. /// -public class UrsaWindow: Window +public class UrsaWindow : Window { + /// + /// The name of the dialog host part in the control template. + /// + public const string PART_DialogHost = "PART_DialogHost"; + + /// + /// Defines the visibility of the full-screen button. + /// + public static readonly StyledProperty IsFullScreenButtonVisibleProperty = + AvaloniaProperty.Register( + nameof(IsFullScreenButtonVisible)); + + /// + /// Defines the visibility of the minimize button. + /// + public static readonly StyledProperty IsMinimizeButtonVisibleProperty = + AvaloniaProperty.Register( + nameof(IsMinimizeButtonVisible), true); + + /// + /// Defines the visibility of the restore button. + /// + public static readonly StyledProperty IsRestoreButtonVisibleProperty = + AvaloniaProperty.Register( + nameof(IsRestoreButtonVisible), true); + + /// + /// Defines the visibility of the close button. + /// + public static readonly StyledProperty IsCloseButtonVisibleProperty = + AvaloniaProperty.Register( + nameof(IsCloseButtonVisible), true); + + /// + /// Defines the visibility of the title bar. + /// + public static readonly StyledProperty IsTitleBarVisibleProperty = AvaloniaProperty.Register( + nameof(IsTitleBarVisible), true); + + /// + /// Defines the visibility of the managed resizer. + /// + public static readonly StyledProperty IsManagedResizerVisibleProperty = + AvaloniaProperty.Register( + nameof(IsManagedResizerVisible)); + + /// + /// Defines the content of the title bar. + /// + public static readonly StyledProperty TitleBarContentProperty = + AvaloniaProperty.Register( + nameof(TitleBarContent)); + + /// + /// Defines the content on the left side of the window. + /// + public static readonly StyledProperty LeftContentProperty = AvaloniaProperty.Register( + nameof(LeftContent)); + + /// + /// Defines the content on the right side of the window. + /// + public static readonly StyledProperty RightContentProperty = + AvaloniaProperty.Register( + nameof(RightContent)); + + /// + /// Defines the margin of the title bar. + /// + public static readonly StyledProperty TitleBarMarginProperty = + AvaloniaProperty.Register( + nameof(TitleBarMargin)); + + private bool _canClose; + + /// + /// Gets the style key override for the control. + /// protected override Type StyleKeyOverride => typeof(UrsaWindow); - public static readonly StyledProperty IsFullScreenButtonVisibleProperty = AvaloniaProperty.Register( - nameof(IsFullScreenButtonVisible)); - + /// + /// Gets or sets a value indicating whether the full-screen button is visible. + /// public bool IsFullScreenButtonVisible { get => GetValue(IsFullScreenButtonVisibleProperty); set => SetValue(IsFullScreenButtonVisibleProperty, value); } - - public static readonly StyledProperty IsMinimizeButtonVisibleProperty = AvaloniaProperty.Register( - nameof(IsMinimizeButtonVisible), true); - + + /// + /// Gets or sets a value indicating whether the minimize button is visible. + /// public bool IsMinimizeButtonVisible { get => GetValue(IsMinimizeButtonVisibleProperty); set => SetValue(IsMinimizeButtonVisibleProperty, value); } - public static readonly StyledProperty IsRestoreButtonVisibleProperty = AvaloniaProperty.Register( - nameof(IsRestoreButtonVisible), true); - + /// + /// Gets or sets a value indicating whether the restore button is visible. + /// public bool IsRestoreButtonVisible { get => GetValue(IsRestoreButtonVisibleProperty); set => SetValue(IsRestoreButtonVisibleProperty, value); } - - public static readonly StyledProperty IsCloseButtonVisibleProperty = AvaloniaProperty.Register( - nameof(IsCloseButtonVisible), true); - + + /// + /// Gets or sets a value indicating whether the close button is visible. + /// public bool IsCloseButtonVisible { get => GetValue(IsCloseButtonVisibleProperty); set => SetValue(IsCloseButtonVisibleProperty, value); } - - public static readonly StyledProperty IsTitleBarVisibleProperty = AvaloniaProperty.Register( - nameof(IsTitleBarVisible), true); - + + /// + /// Gets or sets a value indicating whether the title bar is visible. + /// public bool IsTitleBarVisible { get => GetValue(IsTitleBarVisibleProperty); set => SetValue(IsTitleBarVisibleProperty, value); } - public static readonly StyledProperty IsManagedResizerVisibleProperty = AvaloniaProperty.Register( - nameof(IsManagedResizerVisible)); - + /// + /// Gets or sets a value indicating whether the managed resizer is visible. + /// public bool IsManagedResizerVisible { get => GetValue(IsManagedResizerVisibleProperty); set => SetValue(IsManagedResizerVisibleProperty, value); } - - public static readonly StyledProperty TitleBarContentProperty = AvaloniaProperty.Register( - nameof(TitleBarContent)); - + + /// + /// Gets or sets the content of the title bar. + /// public object? TitleBarContent { get => GetValue(TitleBarContentProperty); set => SetValue(TitleBarContentProperty, value); } - - public static readonly StyledProperty LeftContentProperty = AvaloniaProperty.Register( - nameof(LeftContent)); - + + /// + /// Gets or sets the content on the left side of the window. + /// public object? LeftContent { get => GetValue(LeftContentProperty); set => SetValue(LeftContentProperty, value); } - - public static readonly StyledProperty RightContentProperty = AvaloniaProperty.Register( - nameof(RightContent)); - + + /// + /// Gets or sets the content on the right side of the window. + /// public object? RightContent { get => GetValue(RightContentProperty); set => SetValue(RightContentProperty, value); } - public static readonly StyledProperty TitleBarMarginProperty = AvaloniaProperty.Register( - nameof(TitleBarMargin)); - + /// + /// Gets or sets the margin of the title bar. + /// public Thickness TitleBarMargin { get => GetValue(TitleBarMarginProperty); set => SetValue(TitleBarMarginProperty, value); } + /// + protected override void OnApplyTemplate(TemplateAppliedEventArgs e) + { + base.OnApplyTemplate(e); + var host = e.NameScope.Find(PART_DialogHost); + if (host is not null) LogicalChildren.Add(host); + } + + /// + /// Determines whether the window can close. + /// + /// A task that resolves to true if the window can close; otherwise, false. protected virtual async Task CanClose() { return await Task.FromResult(true); } - - private bool _canClose = false; + + /// + /// Handles the window closing event and determines whether the window should close. + /// + /// The event arguments for the closing event. protected override async void OnClosing(WindowClosingEventArgs e) { VerifyAccess();