diff --git a/src/Avalonia.Controls/HotkeyManager.cs b/src/Avalonia.Controls/HotkeyManager.cs index b76b7fbed5..e89bb177dd 100644 --- a/src/Avalonia.Controls/HotkeyManager.cs +++ b/src/Avalonia.Controls/HotkeyManager.cs @@ -104,11 +104,13 @@ namespace Avalonia.Controls { HotKeyProperty.Changed.Subscribe(args => { + if (args.NewValue.Value is null) return; + var control = args.Sender as IControl; - if (args.OldValue != null || control == null || !(control is ICommandSource)) + if (control is not ICommandSource) { - Logging.Logger.TryGet(Logging.LogEventLevel.Warning, Logging.LogArea.Control)?. - Log(control, $"The element {args.Sender.GetType().Name} does not support binding a HotKey ({args.NewValue})."); + Logging.Logger.TryGet(Logging.LogEventLevel.Warning, Logging.LogArea.Control)?.Log(control, + $"The element {args.Sender.GetType().Name} does not implement ICommandSource and does not support binding a HotKey ({args.NewValue})."); return; }