Listview 如何从Syncfusion列表视图中获取可见项?

Listview 如何从Syncfusion列表视图中获取可见项?,listview,xamarin,xamarin.forms,syncfusion,Listview,Xamarin,Xamarin.forms,Syncfusion,我在Xamarin.Forms项目中工作,并对列表使用Syncfusion SfListView控件 现在我只想在最初的基础上和滚动列表视图之后获得可见的项目。意思是在滚动停止后,我需要通过API获取更新来更新可见项 如何在Xamarin.Forms Syncfusion SfListView中实现这一点 有谁能给出解决办法吗 谢谢。当使用Changed事件滚动时,SfListView允许进行通知。通过使用此事件,您可以根据LastBodyVisibleLineIndex属性和基础集合计数,在S

我在Xamarin.Forms项目中工作,并对列表使用Syncfusion SfListView控件

现在我只想在最初的基础上和滚动列表视图之后获得可见的项目。意思是在滚动停止后,我需要通过API获取更新来更新可见项

如何在Xamarin.Forms Syncfusion SfListView中实现这一点

有谁能给出解决办法吗


谢谢。

当使用
Changed
事件滚动时,
SfListView
允许进行通知。通过使用此事件,您可以根据
LastBodyVisibleLineIndex
属性和基础集合计数,在SfListView中查找是否已到达列表中的最后一项

您可以使用下面的代码

using Syncfusion.ListView.XForms.Control.Helpers;
public partial class MainPage : ContentPage
{
 VisualContainer visualContainer;
bool isAlertShown = false;

public MainPage()
{
    InitializeComponent();
    visualContainer = listView.GetVisualContainer();
    visualContainer.ScrollRows.Changed += ScrollRows_Changed;
}

///<summary>
///To notify when end reached
///</summary>
private void ScrollRows_Changed(object sender, ScrollChangedEventArgs e)
{
    var lastIndex = visualContainer.ScrollRows.LastBodyVisibleLineIndex;

    //To include header if used
    var header = (listView.HeaderTemplate != null && !listView.IsStickyHeader) ? 1 : 0;

    //To include footer if used
    var footer = (listView.FooterTemplate != null && !listView.IsStickyFooter) ? 1 : 0;
    var totalItems = listView.DataSource.DisplayItems.Count + header + footer;

    if ((lastIndex == totalItems - 1))
    {
        if (!isAlertShown)
        {
           // do something to update the visible items by getting updates through API.
            DisplayAlert("Alert", "End of list reached...", "Ok");
            isAlertShown = true;
        }
    }
    else
        isAlertShown = false;
 }
}
使用Syncfusion.ListView.XForms.Control.Helpers;
公共部分类主页:ContentPage
{
视觉容器;
bool-isAlertShown=false;
公共主页()
{
初始化组件();
visualContainer=listView.GetVisualContainer();
visualContainer.ScrollRows.Changed+=ScrollRows\u Changed;
}
///
///到达终点时通知
///
私有无效ScrollRows\u已更改(对象发送方,ScrollChangedEventArgs e)
{
var lastIndex=visualContainer.ScrollRows.LastBodyVisibleLineIndex;
//若使用,则包括标题
var header=(listView.HeaderTemplate!=null&&!listView.IsStickyHeader)?1:0;
//包括页脚(如果使用)
var footer=(listView.FooterTemplate!=null&&!listView.IsStickyFooter)?1:0;
var totalItems=listView.DataSource.DisplayItems.Count+页眉+页脚;
如果((lastIndex==totalItems-1))
{
如果(!isAlertShown)
{
//通过API获取更新来更新可见项。
显示警报(“警报”,“已到达列表末尾…”,“确定”);
isAlertShown=真;
}
}
其他的
isAlertShown=假;
}
}
我们已经检查了我们这边报告的查询“如何从Syncfusion列表视图中获取可见项”。我们想通知您,您可以从VisualContainer的Children属性获取加载时创建的项目。此外,您还可以使用VisualContainer.ScrollRows.LastBodyVisibleLineIndex属性获取最后一个可见项的信息。请从下面找到代码片段,
C#:可视化容器。孩子们将拥有可见项目的详细信息。
公共类行为:行为
{ 
SfListView-ListView;
视觉容器;
受保护的覆盖无效的TachedTo(ContentPage可绑定)
{ 
ListView=bindable.FindByName(“ListView”);
VisualContainer=ListView.GetVisualContainer();
ListView.ScrollStateChanged+=ListView\u ScrollStateChanged;
碱。可粘合的DTO(可粘合);
} 
私有无效滚动视图\u滚动(对象发送方,滚动目标)
{ 
} 
私有无效列表视图\u ScrollStateChanged(对象发送方,ScrollStateChangedEventArgs e)
{ 
if(e.ScrollState==ScrollState.Idle)
{ 
var visibleItems=VisualContainer.Children;
var lastVisibleItem=VisualContainer.ScrollRows.LastBodyVisibleLineIndex;
} 
} 
} 
We have checked the reported query “How to get visible items from Syncfusion list view?” from our side. We would like to inform you that you can get the items created on load from the Children property of the VisualContainer. Also, you can get the information of the last visible item using the VisualContainer.ScrollRows.LastBodyVisibleLineIndex property. Please find the code snippets from the below, 
C#: The VisualContainer.Children will have the details of the visible items.
public class Behavior : Behavior<ContentPage> 
    { 
        SfListView ListView; 
        VisualContainer VisualContainer; 
     
        protected override void OnAttachedTo(ContentPage bindable) 
        { 
            ListView = bindable.FindByName<SfListView>("listView"); 
            VisualContainer = ListView.GetVisualContainer(); 
            ListView.ScrollStateChanged += ListView_ScrollStateChanged; 
            base.OnAttachedTo(bindable); 
        } 
     
        private void ScrollView_Scrolled(object sender, ScrolledEventArgs e) 
        { 
        } 
     
        private void ListView_ScrollStateChanged(object sender, ScrollStateChangedEventArgs e) 
        { 
            if (e.ScrollState == ScrollState.Idle) 
            { 
                var visibleItems = VisualContainer.Children; 
                var lastVisibleItem = VisualContainer.ScrollRows.LastBodyVisibleLineIndex; 
            } 
        } 
    }