C# 在ListView中使用ItemExaming事件向下滚动跳过Xamarin.Forms中的记录
我在Xamarin页面中有C# 在ListView中使用ItemExaming事件向下滚动跳过Xamarin.Forms中的记录,c#,xamarin.forms,xamarin.forms.listview,xamarin.ios-binding,C#,Xamarin.forms,Xamarin.forms.listview,Xamarin.ios Binding,我在Xamarin页面中有ListView。我使用itemseapping事件向下滚动。ListViewCell的高度很大,因此第一个屏幕覆盖第一个viewcell,第二个viewcell的80%部分 为向下滚动加载更多数据的步骤: 最初,当页面加载时,它调用API并在中获得10条记录 EmployerResult列表。将使用添加到ListView中的 数据绑定 有项出现的事件。此事件中存在一个条件。 当最后一个单元格开始出现时,它将调用API并再次追加10 记录在ViewModel的列表对象中
ListView
。我使用itemseapping
事件向下滚动。ListViewCell的高度很大,因此第一个屏幕覆盖第一个viewcell,第二个viewcell的80%部分
为向下滚动加载更多数据的步骤:
项出现的
事件。此事件中存在一个条件。
当最后一个单元格开始出现时,它将调用API并再次追加10
记录在ViewModel的列表对象中public EmployerResultsViewModel()
{
LoadMoreCommand = new RelayCommand(LoadMoreEmployerResult, () => !IsBusy);
EmployerResults = new ObservableRangeCollection<EmployerProfile>();
}
public ObservableRangeCollection<EmployerProfile> EmployerResults { get; set; }
private async void LoadMoreEmployerResult()
{
IsBusy = true;
EmployerResults.AddRange((await _employerApiClient.GetMoreData(pagenumber)));
IsBusy = false;
}
public employeerresultsviewmodel()
{
LoadMoreCommand=new RelayCommand(LoadMoreEmployerResult,()=>!IsBusy);
EmployerResults=新的ObserverAgeCollection();
}
公共ObserverAgeCollection EmployerResults{get;set;}
私有异步void LoadMoreEmployerResult()
{
IsBusy=true;
employeerresults.AddRange((wait_employeerapiclient.GetMoreData(页码));
IsBusy=false;
}
据我所知,您正在尝试进行延迟加载
-首先,您应该如下设置回收策略:CachingStrategy=“RecycleElement”如果您希望获得此处所述的可接受的性能,则应重新测试itemseapping事件的行为
-然后,使用或分析处理您需求的现有组件可能是一个好主意。例如:我所做的是在
LoadMoreEmployerResult
的末尾添加额外的空白单元格,并在该单元格上显示时调用LoadMore。加载更多时,我将删除空白单元格。这是我认为能够解决我的问题的唯一方法
private async void LoadMoreEmployerResult()
{
IsBusy = true;
if(EmployerResults.Last().Name == "")
EmployerResults.RemoveAt(EmployerResults.Count - 1);
List<EmployerProfile> currentPageList= await _employerApiClient.GetMoreData(pagenumber);
if(currentPageList.Count > 0)
{
EmployerResults.AddRange(currentPageList);
EmployerResults.Add(new EmployerProfile());
}
IsBusy = false;
}
private异步void LoadMoreEmployerResult()
{
IsBusy=true;
如果(EmployerResults.Last().Name==“”)
EmployerResults.RemoveAt(EmployerResults.Count-1);
List currentPageList=wait_employeerapiclient.GetMoreData(页码);
如果(currentPageList.Count>0)
{
EmployerResults.AddRange(当前页面列表);
EmployerResults.Add(newemployerProfile());
}
IsBusy=false;
}
您的问题是我正在寻找的解决方案。这是一个很好的主意,但会导致屏幕上出现大量不稳定的滚动和闪烁iOS@Ashi早在2018年,我就已经实现了这一点。
public EmployerResultsViewModel()
{
LoadMoreCommand = new RelayCommand(LoadMoreEmployerResult, () => !IsBusy);
EmployerResults = new ObservableRangeCollection<EmployerProfile>();
}
public ObservableRangeCollection<EmployerProfile> EmployerResults { get; set; }
private async void LoadMoreEmployerResult()
{
IsBusy = true;
EmployerResults.AddRange((await _employerApiClient.GetMoreData(pagenumber)));
IsBusy = false;
}
private async void LoadMoreEmployerResult()
{
IsBusy = true;
if(EmployerResults.Last().Name == "")
EmployerResults.RemoveAt(EmployerResults.Count - 1);
List<EmployerProfile> currentPageList= await _employerApiClient.GetMoreData(pagenumber);
if(currentPageList.Count > 0)
{
EmployerResults.AddRange(currentPageList);
EmployerResults.Add(new EmployerProfile());
}
IsBusy = false;
}