diff --git a/samples/Sandbox/MainWindow.axaml.cs b/samples/Sandbox/MainWindow.axaml.cs index 93378dd736..3d54036d29 100644 --- a/samples/Sandbox/MainWindow.axaml.cs +++ b/samples/Sandbox/MainWindow.axaml.cs @@ -5,40 +5,17 @@ using Avalonia.Win32.WinRT.Composition; namespace Sandbox { - public partial class MainWindow : Window + public class MainWindow : Window { public MainWindow() { - InitializeComponent(); -#if DEBUG + this.InitializeComponent(); 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/tests/Avalonia.Controls.UnitTests/ButtonTests.cs b/tests/Avalonia.Controls.UnitTests/ButtonTests.cs index e7a42c2d93..dcef91589d 100644 --- a/tests/Avalonia.Controls.UnitTests/ButtonTests.cs +++ b/tests/Avalonia.Controls.UnitTests/ButtonTests.cs @@ -295,6 +295,20 @@ namespace Avalonia.Controls.UnitTests target.CommandParameter = false; Assert.False(target.IsEffectivelyEnabled); } + + [Fact] + public void Button_Invokes_Doesnt_Execute_When_Button_Disabled() + { + var target = new Button(); + var raised = 0; + + target.IsEnabled = false; + target.Click += (s, e) => ++raised; + + target.RaiseEvent(new RoutedEventArgs(AccessKeyHandler.AccessKeyPressedEvent)); + + Assert.Equal(1, raised); + } private class TestButton : Button, IRenderRoot {