Browse Source
Merge pull request #7206 from Abdesol/master
Disabled button can be pressed issue/bug
pull/7210/head
Max Katz
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
24 additions and
7 deletions
-
src/Avalonia.Controls/Button.cs
-
tests/Avalonia.Controls.UnitTests/ButtonTests.cs
|
|
|
@ -304,15 +304,18 @@ namespace Avalonia.Controls |
|
|
|
/// </summary>
|
|
|
|
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; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -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(0, raised); |
|
|
|
} |
|
|
|
|
|
|
|
private class TestButton : Button, IRenderRoot |
|
|
|
{ |
|
|
|
|