diff --git a/src/Avalonia.Controls/Button.cs b/src/Avalonia.Controls/Button.cs index b4a9b2db4455..429e263688ad 100644 --- a/src/Avalonia.Controls/Button.cs +++ b/src/Avalonia.Controls/Button.cs @@ -291,7 +291,7 @@ protected override void OnKeyDown(KeyEventArgs e) break; case Key.Space: // Handle Space only current focus control - if (TopLevel.GetTopLevel(this)?.FocusManager?.GetFocusedElement() == this) + if (IsFocused) { if (ClickMode == ClickMode.Press) { @@ -314,7 +314,7 @@ protected override void OnKeyDown(KeyEventArgs e) protected override void OnKeyUp(KeyEventArgs e) { // Handle Space only current focus control - if (e.Key == Key.Space && TopLevel.GetTopLevel(this)?.FocusManager?.GetFocusedElement() == this) + if (e.Key == Key.Space && IsFocused) { if (ClickMode == ClickMode.Release) {