Browse Source

removed focus fix and added test in sandbox

pull/7206/head
abdesol 4 years ago
parent
commit
7f20078e4f
  1. 27
      samples/Sandbox/MainWindow.axaml.cs
  2. 17
      src/Avalonia.Controls/Button.cs

27
samples/Sandbox/MainWindow.axaml.cs

@ -5,17 +5,40 @@ using Avalonia.Win32.WinRT.Composition;
namespace Sandbox namespace Sandbox
{ {
public class MainWindow : Window public partial class MainWindow : Window
{ {
public MainWindow() public MainWindow()
{ {
this.InitializeComponent(); InitializeComponent();
#if DEBUG
this.AttachDevTools(); this.AttachDevTools();
#endif
} }
private void InitializeComponent() private void InitializeComponent()
{ {
AvaloniaXamlLoader.Load(this); 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.";
};
} }
} }
} }

17
src/Avalonia.Controls/Button.cs

@ -304,15 +304,18 @@ namespace Avalonia.Controls
/// </summary> /// </summary>
protected virtual void OnClick() protected virtual void OnClick()
{ {
OpenFlyout(); if (IsEffectivelyEnabled)
{
OpenFlyout();
var e = new RoutedEventArgs(ClickEvent); var e = new RoutedEventArgs(ClickEvent);
RaiseEvent(e); RaiseEvent(e);
if (!e.Handled && Command?.CanExecute(CommandParameter) == true) if (!e.Handled && Command?.CanExecute(CommandParameter) == true)
{ {
Command.Execute(CommandParameter); Command.Execute(CommandParameter);
e.Handled = true; e.Handled = true;
}
} }
} }

Loading…
Cancel
Save