diff --git a/samples/Sandbox/MainWindow.axaml.cs b/samples/Sandbox/MainWindow.axaml.cs index 3d54036d29..93378dd736 100644 --- a/samples/Sandbox/MainWindow.axaml.cs +++ b/samples/Sandbox/MainWindow.axaml.cs @@ -5,17 +5,40 @@ using Avalonia.Win32.WinRT.Composition; namespace Sandbox { - public class MainWindow : Window + public partial class MainWindow : Window { public MainWindow() { - this.InitializeComponent(); + InitializeComponent(); +#if DEBUG this.AttachDevTools(); +#endif } private void InitializeComponent() { AvaloniaXamlLoader.Load(this); + + var button = new Button + { + Content = "Tabulate to this button" + }; + + Content = button; + button.GotFocus += (_, _) => + { + button.IsEnabled = false; + button.Content = + $"Now this button is disabled ({nameof(IsEnabled)}:{button.IsEnabled},{nameof(IsEffectivelyEnabled)}:{button.IsEffectivelyEnabled}), but you can still press Enter"; + button.KeyDown += (_, _) => + { + button.Content = "button got fired by KeyDown event"; + }; + }; + button.Click += (_, _) => + { + button.Content = "It just has been clicked."; + }; } } } diff --git a/src/Avalonia.Controls/Button.cs b/src/Avalonia.Controls/Button.cs index 8b22cdd4ec..8537c9acbc 100644 --- a/src/Avalonia.Controls/Button.cs +++ b/src/Avalonia.Controls/Button.cs @@ -304,15 +304,18 @@ namespace Avalonia.Controls /// protected virtual void OnClick() { - OpenFlyout(); + if (IsEffectivelyEnabled) + { + OpenFlyout(); - var e = new RoutedEventArgs(ClickEvent); - RaiseEvent(e); + var e = new RoutedEventArgs(ClickEvent); + RaiseEvent(e); - if (!e.Handled && Command?.CanExecute(CommandParameter) == true) - { - Command.Execute(CommandParameter); - e.Handled = true; + if (!e.Handled && Command?.CanExecute(CommandParameter) == true) + { + Command.Execute(CommandParameter); + e.Handled = true; + } } }