diff --git a/src/Avalonia.Controls/Automation/Peers/ControlAutomationPeer.cs b/src/Avalonia.Controls/Automation/Peers/ControlAutomationPeer.cs index e8fb6b75ad..d04dfec3e8 100644 --- a/src/Avalonia.Controls/Automation/Peers/ControlAutomationPeer.cs +++ b/src/Avalonia.Controls/Automation/Peers/ControlAutomationPeer.cs @@ -88,10 +88,10 @@ namespace Avalonia.Automation.Peers if (string.IsNullOrWhiteSpace(result) && GetLabeledBy() is AutomationPeer labeledBy) { - return labeledBy.GetName(); + result = labeledBy.GetName(); } - return null; + return result; } protected override AutomationPeer? GetParentCore() diff --git a/src/Avalonia.Controls/Chrome/CaptionButtons.cs b/src/Avalonia.Controls/Chrome/CaptionButtons.cs index f5fcbed9fb..90dd14c703 100644 --- a/src/Avalonia.Controls/Chrome/CaptionButtons.cs +++ b/src/Avalonia.Controls/Chrome/CaptionButtons.cs @@ -15,6 +15,7 @@ namespace Avalonia.Controls.Chrome [PseudoClasses(":minimized", ":normal", ":maximized", ":fullscreen")] public class CaptionButtons : TemplatedControl { + private Button? _restoreButton; private IDisposable? _disposables; /// @@ -28,14 +29,23 @@ namespace Avalonia.Controls.Chrome { HostWindow = hostWindow; - _disposables = HostWindow.GetObservable(Window.WindowStateProperty) - .Subscribe(x => - { - PseudoClasses.Set(":minimized", x == WindowState.Minimized); - PseudoClasses.Set(":normal", x == WindowState.Normal); - PseudoClasses.Set(":maximized", x == WindowState.Maximized); - PseudoClasses.Set(":fullscreen", x == WindowState.FullScreen); - }); + _disposables = new CompositeDisposable + { + HostWindow.GetObservable(Window.CanResizeProperty) + .Subscribe(x => + { + if (_restoreButton is not null) + _restoreButton.IsEnabled = x; + }), + HostWindow.GetObservable(Window.WindowStateProperty) + .Subscribe(x => + { + PseudoClasses.Set(":minimized", x == WindowState.Minimized); + PseudoClasses.Set(":normal", x == WindowState.Normal); + PseudoClasses.Set(":maximized", x == WindowState.Maximized); + PseudoClasses.Set(":fullscreen", x == WindowState.FullScreen); + }), + }; } } @@ -94,6 +104,9 @@ namespace Avalonia.Controls.Chrome restoreButton.Click += (sender, e) => OnRestore(); minimiseButton.Click += (sender, e) => OnMinimize(); fullScreenButton.Click += (sender, e) => OnToggleFullScreen(); + + restoreButton.IsEnabled = HostWindow?.CanResize ?? true; + _restoreButton = restoreButton; } } } diff --git a/src/Avalonia.Native/WindowImpl.cs b/src/Avalonia.Native/WindowImpl.cs index 5d0e6a2d18..817fe3d080 100644 --- a/src/Avalonia.Native/WindowImpl.cs +++ b/src/Avalonia.Native/WindowImpl.cs @@ -21,6 +21,7 @@ namespace Avalonia.Native private DoubleClickHelper _doubleClickHelper; private readonly ITopLevelNativeMenuExporter _nativeMenuExporter; private readonly AvaloniaNativeTextInputMethod _inputMethod; + private bool _canResize = true; internal WindowImpl(IAvaloniaNativeFactory factory, AvaloniaNativePlatformOptions opts, AvaloniaNativeGlPlatformGraphics glFeature) : base(factory, opts, glFeature) @@ -75,6 +76,7 @@ namespace Avalonia.Native public void CanResize(bool value) { + _canResize = value; _native.SetCanResize(value.AsComBool()); } @@ -137,14 +139,10 @@ namespace Avalonia.Native { if (_doubleClickHelper.IsDoubleClick(e.Timestamp, e.Position)) { - // TOGGLE WINDOW STATE. - if (WindowState == WindowState.Maximized || WindowState == WindowState.FullScreen) + if (_canResize) { - WindowState = WindowState.Normal; - } - else - { - WindowState = WindowState.Maximized; + WindowState = WindowState is WindowState.Maximized or WindowState.FullScreen ? + WindowState.Normal : WindowState.Maximized; } } else diff --git a/src/Avalonia.Themes.Fluent/Controls/CaptionButtons.xaml b/src/Avalonia.Themes.Fluent/Controls/CaptionButtons.xaml index 71ae012289..666717acde 100644 --- a/src/Avalonia.Themes.Fluent/Controls/CaptionButtons.xaml +++ b/src/Avalonia.Themes.Fluent/Controls/CaptionButtons.xaml @@ -48,7 +48,8 @@