From c7a21d7268aad472e9022777b626120cdc6b29e3 Mon Sep 17 00:00:00 2001 From: Giuseppe Lippolis Date: Fri, 9 Oct 2020 09:51:54 +0200 Subject: [PATCH] Removed CommandParameter Binding --- src/Avalonia.Controls/HotkeyManager.cs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Avalonia.Controls/HotkeyManager.cs b/src/Avalonia.Controls/HotkeyManager.cs index f210ecfdaf..dabc35dd24 100644 --- a/src/Avalonia.Controls/HotkeyManager.cs +++ b/src/Avalonia.Controls/HotkeyManager.cs @@ -1,7 +1,6 @@ using System; using System.Windows.Input; using Avalonia.Controls.Utils; -using Avalonia.Data.Core; using Avalonia.Input; namespace Avalonia.Controls @@ -22,9 +21,12 @@ namespace Avalonia.Controls private ICommand GetCommand() => CommandSource.Command; - public bool CanExecute(object parameter) => CommandSource.IsEffectivelyEnabled; + public bool CanExecute(object parameter) => + CommandSource.Command?.CanExecute(CommandSource.CommandParameter) == true + && CommandSource.IsEffectivelyEnabled; - public void Execute(object parameter) => GetCommand()?.Execute(parameter); + public void Execute(object parameter) => + GetCommand()?.Execute(CommandSource.CommandParameter); #pragma warning disable 67 // Event not used public event EventHandler CanExecuteChanged; @@ -38,7 +40,6 @@ namespace Avalonia.Controls private TopLevel _root; private IDisposable _parentSub; private IDisposable _hotkeySub; - private IDisposable _commandParameterChangedSubscriber; private KeyGesture _hotkey; private readonly HotkeyCommandWrapper _wrapper; private KeyBinding _binding; @@ -79,7 +80,6 @@ namespace Avalonia.Controls { if (_root != null && _binding != null) _root.KeyBindings.Remove(_binding); - _commandParameterChangedSubscriber?.Dispose(); _binding = null; } @@ -87,9 +87,7 @@ namespace Avalonia.Controls { if (_root != null && _hotkey != null) { - _binding = new KeyBinding() {Gesture = _hotkey, Command = _wrapper}; - _commandParameterChangedSubscriber = _binding.Bind(KeyBinding.CommandParameterProperty - , ExpressionObserver.Create(((ICommandSource)_control), o => o.CommandParameter)); + _binding = new KeyBinding() { Gesture = _hotkey, Command = _wrapper }; _root.KeyBindings.Add(_binding); } }