Improve ScrollToSelectedItemBehavior
MODIFY
WalletWasabi.Fluent/Behaviors/ScrollToSelectedItemBehavior.cs
WalletWasabi.Fluent/Behaviors/ScrollToSelectedItemBehavior.cs
@@ -9,23 +9,22 @@ public class ScrollToSelectedItemBehavior : AttachedToVisualTreeBehavior<Avaloni
{
protected override void OnAttachedToVisualTree(CompositeDisposable disposable)
{
- if (AssociatedObject is not { SelectionInteraction: { } selection, RowSelection: { } rowSelection })
+ if (AssociatedObject is { SelectionInteraction: { } selection, RowSelection: { } rowSelection })
{
- return;
- }
-
Observable.FromEventPattern(selection, nameof(selection.SelectionChanged))
.Select(x => rowSelection.SelectedIndex.FirstOrDefault())
.WhereNotNull()
- .Do(
- index =>
+ .Do(ScrollToItemIndex)
+ .Subscribe()
+ .DisposeWith(disposable);
+ }
+ }
+
+ private void ScrollToItemIndex(int index)
{
- if (AssociatedObject.RowsPresenter is not null)
+ if (AssociatedObject is { RowsPresenter: { } rowsPresenter })
{
- AssociatedObject.RowsPresenter.BringIntoView(index);
+ rowsPresenter.BringIntoView(index);
}
- })
- .Subscribe()
- .DisposeWith(disposable);
}
}

Improve ScrollToSelectedItemBehavior