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

17
src/Avalonia.Controls/Button.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;
}
}
}

Loading…
Cancel
Save