Code cleanup on Key Down behaviors
MODIFY
WalletWasabi.Fluent/Behaviors/ButtonExecuteCommandOnKeyDownBehavior.cs
WalletWasabi.Fluent/Behaviors/ButtonExecuteCommandOnKeyDownBehavior.cs
@@ -2,6 +2,7 @@ using System.Reactive.Disposables;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
+using Avalonia.Interactivity;
using Avalonia.VisualTree;
namespace WalletWasabi.Fluent.Behaviors;
@@ -36,9 +37,8 @@ public class ButtonExecuteCommandOnKeyDownBehavior : AttachedToVisualTreeBehavio
if (button.GetVisualRoot() is IInputElement inputRoot)
{
- inputRoot.AddHandler(InputElement.KeyDownEvent, RootDefaultKeyDown);
-
- disposable.Add(Disposable.Create(() => inputRoot.RemoveHandler(InputElement.KeyDownEvent, RootDefaultKeyDown)));
+ inputRoot.AddDisposableHandler(InputElement.KeyDownEvent, RootDefaultKeyDown)
+ .DisposeWith(disposable);
}
}

MODIFY
WalletWasabi.Fluent/Behaviors/ExecuteCommandOnKeyDownBehavior.cs
WalletWasabi.Fluent/Behaviors/ExecuteCommandOnKeyDownBehavior.cs
@@ -71,7 +71,7 @@ public class ExecuteCommandOnKeyDownBehavior : AttachedToVisualTreeBehavior<Cont
if (Key is { } && e.Key == Key && control.IsVisible && control.IsEnabled && IsEnabled)
{
- if (!e.Handled && Command.CanExecute(CommandParameter))
+ if (!e.Handled && Command?.CanExecute(CommandParameter) == true)
{
Command.Execute(CommandParameter);
e.Handled = true;

Code cleanup on Key Down behaviors