From 445ea0b9228fa13c11636bef45f5782ebaf3fe32 Mon Sep 17 00:00:00 2001 From: erri120 Date: Tue, 7 Dec 2021 20:07:22 +0100 Subject: [PATCH] Fix condition in HotKeyProperty.Changed handler (#7096) * Fix condition in HotKeyProperty.Changed handler See #7095 for more information. The condition originally existed to warn about binding the HotKeyProperty to a Control that does not implement ICommandSource. * Ignore null HotKey in HotKeyProperty.Changed --- src/Avalonia.Controls/HotkeyManager.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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; }