using System;
using System.Reactive.Disposables;
using Avalonia.Controls;
namespace Avalonia.Xaml.Interactions.Custom;
///
///
///
public class ScrollToItemIndexBehavior : AttachedToVisualTreeBehavior
{
///
///
///
public static readonly StyledProperty?> ItemIndexProperty =
AvaloniaProperty.Register?>(nameof(ItemIndex));
///
///
///
public IObservable? ItemIndex
{
get => GetValue(ItemIndexProperty);
set => SetValue(ItemIndexProperty, value);
}
///
///
///
///
protected override void OnAttachedToVisualTree(CompositeDisposable disposables)
{
var disposable = ItemIndex?.Subscribe(index =>
{
AssociatedObject?.ScrollIntoView(index);
});
if (disposable is not null)
{
disposables.Add(disposable);
}
}
}