use disposing behavior for other behaviors.
MODIFY
WalletWasabi.Fluent/Behaviors/FocusNextItemBehavior.cs
WalletWasabi.Fluent/Behaviors/FocusNextItemBehavior.cs
using System;
+using System.Reactive.Disposables;
+using System.Reactive.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
-using Avalonia.Xaml.Interactivity;
using ReactiveUI;
namespace WalletWasabi.Fluent.Behaviors
{
- internal class FocusNextItemBehavior : Behavior<Control>
+ internal class FocusNextItemBehavior : DisposingBehavior<Control>
{
- private IDisposable _disposable;
-
public static readonly StyledProperty<bool> IsFocusedProperty =
AvaloniaProperty.Register<FocusNextItemBehavior, bool>(nameof(IsFocused), true);
@@ -20,28 +19,16 @@ namespace WalletWasabi.Fluent.Behaviors
set => SetValue(IsFocusedProperty, value);
}
- protected override void OnAttached()
+ protected override void OnAttached(CompositeDisposable disposables)
{
- base.OnAttached();
-
- _disposable?.Dispose();
-
- _disposable = this.WhenAnyValue(x => x.IsFocused)
- .Subscribe(x =>
+ this.WhenAnyValue(x => x.IsFocused)
+ .Where(x => x == false)
+ .Subscribe(
+ _ =>
{
- if (!x)
- {
- var nextToFocus = KeyboardNavigationHandler.GetNext(AssociatedObject, NavigationDirection.Next);
- nextToFocus.Focus();
- }
- });
- }
-
- protected override void OnDetaching()
- {
- base.OnDetaching();
-
- _disposable?.Dispose();
+ KeyboardNavigationHandler.GetNext(AssociatedObject!, NavigationDirection.Next)?.Focus();
+ })
+ .DisposeWith(disposables);
}
}
}
\ No newline at end of file

MODIFY
WalletWasabi.Fluent/Behaviors/SplitViewAutoBehavior.cs
WalletWasabi.Fluent/Behaviors/SplitViewAutoBehavior.cs
using Avalonia;
using Avalonia.Controls;
-using Avalonia.Xaml.Interactivity;
using System;
using System.Reactive.Disposables;
using System.Reactive.Linq;
@@ -8,12 +7,10 @@ using ReactiveUI;
namespace WalletWasabi.Fluent.Behaviors
{
- public class SplitViewAutoBehavior : Behavior<SplitView>
+ public class SplitViewAutoBehavior : DisposingBehavior<SplitView>
{
private bool _sidebarWasForceClosed;
- private CompositeDisposable Disposables { get; set; }
-
public static readonly StyledProperty<double> CollapseThresholdProperty =
AvaloniaProperty.Register<SplitViewAutoBehavior, double>(nameof(CollapseThreshold));
@@ -41,37 +38,34 @@ namespace WalletWasabi.Fluent.Behaviors
set => SetValue(CollapseOnClickActionProperty, value);
}
- protected override void OnAttached()
- {
- Disposables = new CompositeDisposable
+ protected override void OnAttached(CompositeDisposable disposables)
{
- AssociatedObject.WhenAnyValue(x => x.Bounds)
+ AssociatedObject!.WhenAnyValue(x => x.Bounds)
.DistinctUntilChanged()
.Subscribe(SplitViewBoundsChanged)
- };
+ .DisposeWith(disposables);
+
ToggleAction = OnToggleAction;
CollapseOnClickAction = OnCollapseOnClickAction;
-
- base.OnAttached();
}
private void OnCollapseOnClickAction()
{
- if (AssociatedObject.Bounds.Width <= CollapseThreshold && AssociatedObject.IsPaneOpen)
+ if (AssociatedObject!.Bounds.Width <= CollapseThreshold && AssociatedObject!.IsPaneOpen)
{
- AssociatedObject.IsPaneOpen = false;
+ AssociatedObject!.IsPaneOpen = false;
}
}
private void OnToggleAction()
{
- if (AssociatedObject.Bounds.Width > CollapseThreshold)
+ if (AssociatedObject!.Bounds.Width > CollapseThreshold)
{
- _sidebarWasForceClosed = AssociatedObject.IsPaneOpen;
+ _sidebarWasForceClosed = AssociatedObject!.IsPaneOpen;
}
- AssociatedObject.IsPaneOpen = !AssociatedObject.IsPaneOpen;
+ AssociatedObject!.IsPaneOpen = !AssociatedObject!.IsPaneOpen;
}
private void SplitViewBoundsChanged(Rect x)
@@ -100,12 +94,5 @@ namespace WalletWasabi.Fluent.Behaviors
}
}
}
-
- protected override void OnDetaching()
- {
- base.OnDetaching();
-
- Disposables?.Dispose();
- }
}
}

use disposing behavior for other behaviors.