From f1f2df8dd48d42ddc7cc669235988b38cf24b259 Mon Sep 17 00:00:00 2001 From: Giuseppe Lippolis Date: Fri, 25 Sep 2020 17:32:26 +0200 Subject: [PATCH] Fixes Issue #4734 : HotKeys trigger command when control is disabled --- src/Avalonia.Controls/HotkeyManager.cs | 2 +- src/Avalonia.Input/ICommandSource.cs | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/HotkeyManager.cs b/src/Avalonia.Controls/HotkeyManager.cs index b104b7a9a8..f210ecfdaf 100644 --- a/src/Avalonia.Controls/HotkeyManager.cs +++ b/src/Avalonia.Controls/HotkeyManager.cs @@ -22,7 +22,7 @@ namespace Avalonia.Controls private ICommand GetCommand() => CommandSource.Command; - public bool CanExecute(object parameter) => GetCommand()?.CanExecute(parameter) ?? false; + public bool CanExecute(object parameter) => CommandSource.IsEffectivelyEnabled; public void Execute(object parameter) => GetCommand()?.Execute(parameter); diff --git a/src/Avalonia.Input/ICommandSource.cs b/src/Avalonia.Input/ICommandSource.cs index b0dd75e12e..ba2e8eed4e 100644 --- a/src/Avalonia.Input/ICommandSource.cs +++ b/src/Avalonia.Input/ICommandSource.cs @@ -27,5 +27,10 @@ namespace Avalonia.Input /// /// void CanExecuteChanged(object sender, System.EventArgs e); + + /// + /// Gets a value indicating whether this control and all its parents are enabled. + /// + bool IsEffectivelyEnabled { get; } } }