Я был создан ListView, который имеет бесконечную прокрутку с помощью ObservableRangeCollection. Он отлично работает на Android, но на iOS он запускается, когда он добавляет новые элементы. Paginating выполняется с поведением. ListView - это FlowListView. Вот XAML:Бесконечный ListView на iOS после обновления переходов к первому элементу
...
FlowItemsSource="{Binding Profiles.Result}
...
<controls:FlowListView.Behaviors>
<behaviors:FlowListViewPaginating
Command="{Binding LoadMoreCommand}"
Converter="{StaticResource ItemVisibilityConverter}">
</behaviors:FlowListViewPaginating>
</controls:FlowListView.Behaviors>
...
Поведение:
public class FlowListViewPaginating : Behavior<FlowListView>
{
public FlowListView AssosiatedObject { get; private set; }
public static readonly BindableProperty CommandProperty =
BindableProperty.Create("Command", typeof(DelegateCommand<Profile>), typeof(FlowListViewPaginating), null);
public static readonly BindableProperty InputConverterProperty =
BindableProperty.Create("Converter", typeof(IValueConverter), typeof(FlowListViewPaginating), null);
public DelegateCommand<Profile> Command
{
get { return (DelegateCommand<Profile>)GetValue(CommandProperty); }
set { SetValue(CommandProperty, value); }
}
public IValueConverter Converter
{
get { return (IValueConverter)GetValue(InputConverterProperty); }
set { SetValue(InputConverterProperty, value); }
}
protected override void OnAttachedTo(FlowListView bindable)
{
base.OnAttachedTo(bindable);
AssosiatedObject = bindable;
bindable.BindingContextChanged += OnBindingContextChanged;
bindable.ItemAppearing += OnItemAppearing;
}
protected override void OnDetachingFrom(FlowListView bindable)
{
base.OnDetachingFrom(bindable);
bindable.BindingContextChanged -= OnBindingContextChanged;
bindable.ItemAppearing -= OnItemAppearing;
AssosiatedObject = null;
}
private void OnItemAppearing(object sender, ItemVisibilityEventArgs e)
{
var flowListView = (FlowListView)sender;
if (flowListView.IsRefreshing) return;
if (Command == null) return;
var parameter = Converter.Convert(e, typeof(object), null, null) as Profile;
if (Command.CanExecute(parameter))
Command.Execute(parameter);
}
protected void OnBindingContextChanged(object sender, EventArgs e)
{
OnBindingContextChanged();
}
protected override void OnBindingContextChanged()
{
base.OnBindingContextChanged();
BindingContext = AssosiatedObject.BindingContext;
}
}
конвертер для поведения:
public class ItemVisibilityEventConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var eventArgs = value as ItemVisibilityEventArgs;
var collection = eventArgs?.Item as System.Collections.ObjectModel.ObservableCollection<object>;
return collection[0];
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
Моя коллекция:
public NotifyTask<ObservableRangeCollection<Profile>> Profiles { get; set; }
NotifyTask
имеет nothi ng делать с коллекцией. Это просто обертка.
метод, где я добавлять элементы:
private async Task OnLoadMore(Profile lastProfile)
{
IsBusy = true;
_pageNumber++;
Profiles.Result.AddRange(await _manager.GetProfilesAsync(_parameters.NextPage()));
IsBusy = false;
}
Что такое 'FlowListView'? Это не часть Xamarin.Forms – Krumelur
@Krumelur Вот он: https://github.com/daniel-luberda/DLToolkit.Forms.Controls/tree/master/FlowListView –
Вам стоит подумать над тем, чтобы поднимать проблему. https://github.com/daniel-luberda/DLToolkit.Forms.Controls/issues – Krumelur