diff --git a/src/AtomUI.Base/OperatingSystemType.cs b/src/AtomUI.Base/OperatingSystemType.cs index e47c55d75..3928dd7c9 100644 --- a/src/AtomUI.Base/OperatingSystemType.cs +++ b/src/AtomUI.Base/OperatingSystemType.cs @@ -1,6 +1,6 @@ namespace AtomUI; -public enum OperatingSystemType +public enum OperationSystemType { Windows, macOS, diff --git a/src/AtomUI.Controls/IOperationSystemAware.cs b/src/AtomUI.Controls/IOperationSystemAware.cs new file mode 100644 index 000000000..ac98184b2 --- /dev/null +++ b/src/AtomUI.Controls/IOperationSystemAware.cs @@ -0,0 +1,15 @@ +using Avalonia; + +namespace AtomUI.Controls; + +public interface IOperationSystemAware +{ + OperationSystemType OperationSystemType { get; } +} + +public abstract class OperationSystemAwareControlProperty : AvaloniaObject +{ + public const string OperationSystemPropertyName = "OperationSystemType"; + public static readonly StyledProperty OperationSystemTypeProperty = + AvaloniaProperty.Register(OperationSystemPropertyName, OperationSystemType.Unknown); +} diff --git a/src/AtomUI.Controls/Window/Themes/WindowTheme.axaml b/src/AtomUI.Controls/Window/Themes/WindowTheme.axaml index 91b5c3843..38de119bb 100644 --- a/src/AtomUI.Controls/Window/Themes/WindowTheme.axaml +++ b/src/AtomUI.Controls/Window/Themes/WindowTheme.axaml @@ -51,10 +51,10 @@ - - diff --git a/src/AtomUI.Controls/Window/Window.cs b/src/AtomUI.Controls/Window/Window.cs index ef4f68f68..792f1da89 100644 --- a/src/AtomUI.Controls/Window/Window.cs +++ b/src/AtomUI.Controls/Window/Window.cs @@ -15,7 +15,7 @@ namespace AtomUI.Controls; using AvaloniaWindow = Avalonia.Controls.Window; -public class Window : AvaloniaWindow, IDisposable +public class Window : AvaloniaWindow, IOperationSystemAware, IDisposable { #region 公共属性定义 @@ -64,6 +64,9 @@ public class Window : AvaloniaWindow, IDisposable public static readonly DirectProperty MacOSTitleBarMarginProperty = AvaloniaProperty.RegisterDirect(nameof (MacOSTitleBarMargin), o => o.MacOSTitleBarMargin); + + public static readonly StyledProperty OperationSystemTypeProperty = + OperationSystemAwareControlProperty.OperationSystemTypeProperty.AddOwner(); public double TitleFontSize { @@ -155,7 +158,13 @@ public class Window : AvaloniaWindow, IDisposable private set => SetAndRaise(MacOSTitleBarMarginProperty, ref _macOSTitleBarMargin, value); } private Thickness _macOSTitleBarMargin; - + + public OperationSystemType OperationSystemType + { + get => GetValue(OperationSystemTypeProperty); + private set => SetValue(OperationSystemTypeProperty, value); + } + #endregion #region 内部属性定义 @@ -170,24 +179,11 @@ public class Window : AvaloniaWindow, IDisposable nameof(EffectiveCornerRadius), o => o.EffectiveCornerRadius); - internal static readonly DirectProperty OperatingSystemTypeProperty = - AvaloniaProperty.RegisterDirect( - nameof(OperatingSystemType), - o => o.OperatingSystemType); - internal static readonly DirectProperty IsUseNativeResizerProperty = AvaloniaProperty.RegisterDirect( nameof(IsUseNativeResizer), o => o.IsUseNativeResizer); - private OperatingSystemType _operatingSystemType; - - internal OperatingSystemType OperatingSystemType - { - get => _operatingSystemType; - private set => SetAndRaise(OperatingSystemTypeProperty, ref _operatingSystemType, value); - } - private CornerRadius _effectiveCornerRadius; internal CornerRadius EffectiveCornerRadius @@ -228,22 +224,22 @@ public class Window : AvaloniaWindow, IDisposable ScalingChanged += HandleScalingChanged; if (OperatingSystem.IsWindows()) { - OperatingSystemType = OperatingSystemType.Windows; + OperationSystemType = OperationSystemType.Windows; } else if (OperatingSystem.IsMacOS() || OperatingSystem.IsMacCatalyst()) { - OperatingSystemType = OperatingSystemType.macOS; + OperationSystemType = OperationSystemType.macOS; } else if (OperatingSystem.IsLinux()) { - OperatingSystemType = OperatingSystemType.Linux; + OperationSystemType = OperationSystemType.Linux; } else { - OperatingSystemType = OperatingSystemType.Unknown; + OperationSystemType = OperationSystemType.Unknown; } - if (OperatingSystemType == OperatingSystemType.Linux) + if (OperationSystemType == OperationSystemType.Linux) { IsUseNativeResizer = false; }