fix disposing on enable behavior.
MODIFY
WalletWasabi.Fluent/Behaviors/FocusOnEnableBehavior.cs
WalletWasabi.Fluent/Behaviors/FocusOnEnableBehavior.cs
using Avalonia;
-using Avalonia.Controls;
-using Avalonia.Xaml.Interactivity;
using System;
+using System.Reactive.Disposables;
using System.Reactive.Linq;
+using Avalonia.Controls;
+using Avalonia.Input;
namespace WalletWasabi.Fluent.Behaviors
{
- public class FocusOnEnableBehavior : Behavior<Control>
- {
- protected override void OnAttached()
+ public class FocusOnEnableBehavior : DisposingBehavior<Control>
{
- base.OnAttached();
-
- Observable.
- FromEventPattern<AvaloniaPropertyChangedEventArgs>(AssociatedObject, nameof(AssociatedObject.PropertyChanged))
- .Select(x => x.EventArgs)
- .Where(x => x.Property.Name == nameof(AssociatedObject.IsEffectivelyEnabled) && x.NewValue is { } && (bool)x.NewValue == true)
- .Subscribe(_ => AssociatedObject!.Focus());
- }
-
- protected override void OnDetaching()
+ protected override void OnAttached(CompositeDisposable disposables)
{
- base.OnDetaching();
+ AssociatedObject
+ .GetObservable(InputElement.IsEffectivelyEnabledProperty)
+ .Where(x => x)
+ .Subscribe(_ => AssociatedObject!.Focus())
+ .DisposeWith(disposables);
}
}
}
\ No newline at end of file

fix disposing on enable behavior.