Browse Source

Button_Invokes_Doesnt_Execute_When_Button_Disabled test added

pull/7206/head
abdesol 4 years ago
parent
commit
845ff07f1f
  1. 27
      samples/Sandbox/MainWindow.axaml.cs
  2. 14
      tests/Avalonia.Controls.UnitTests/ButtonTests.cs

27
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.";
};
}
}
}

14
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
{

Loading…
Cancel
Save