Browse Source

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
pull/7102/head
erri120 5 years ago
committed by GitHub
parent
commit
445ea0b922
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      src/Avalonia.Controls/HotkeyManager.cs

8
src/Avalonia.Controls/HotkeyManager.cs

@ -104,11 +104,13 @@ namespace Avalonia.Controls
{ {
HotKeyProperty.Changed.Subscribe(args => HotKeyProperty.Changed.Subscribe(args =>
{ {
if (args.NewValue.Value is null) return;
var control = args.Sender as IControl; 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)?. Logging.Logger.TryGet(Logging.LogEventLevel.Warning, Logging.LogArea.Control)?.Log(control,
Log(control, $"The element {args.Sender.GetType().Name} does not support binding a HotKey ({args.NewValue})."); $"The element {args.Sender.GetType().Name} does not implement ICommandSource and does not support binding a HotKey ({args.NewValue}).");
return; return;
} }

Loading…
Cancel
Save