Xamarin,ListView,如何确定ListView何时滚动到中间?

Xamarin,ListView,如何确定ListView何时滚动到中间?,listview,events,xamarin.forms,scroll,Listview,Events,Xamarin.forms,Scroll,我想在ListView滚动到中间时调用一个方法 我有列表视图 <ListView x:Name="myListView"> ... </ListView> myListView.Scrolled侦听器: public void ScrolledListener(object sender, ScrolledEventArgs args) { ... var scrollView = (ListView)sender; bool isNeededMoreParticipa

我想在ListView滚动到中间时调用一个方法

我有列表视图

<ListView x:Name="myListView">
...
</ListView>
myListView.Scrolled侦听器:

public void ScrolledListener(object sender, ScrolledEventArgs args)
{
...
var scrollView = (ListView)sender;
bool isNeededMoreParticipants =
 args.ScrollY >
 (int)(scrollView.Height - scrollView.Height / 2); //Height - is not what I expected. I need the maximum size of ScrollY
...
}

如何确定ListView何时滚动到中间?

您似乎想要获取ListView的内容大小。您可以预先设置
ViewCell
RowHeight
的高度(设置为静态值或使用数据绑定),如

public void ScrolledListener(object sender, ScrolledEventArgs args)
{
...
var scrollView = (ListView)sender;
bool isNeededMoreParticipants =
 args.ScrollY >
 (int)(scrollView.Height - scrollView.Height / 2); //Height - is not what I expected. I need the maximum size of ScrollY
...
}
<ListView x:Name="MyListView" Scrolled="ListView_Scrolled" ItemsSource="{Binding MyItems}" RowHeight="60">
<DataTemplate>

   <ViewCell>

      <StackLayout HeightRequest="{Binding xxx}">



      </StackLayout>

   </ViewCell>

</DataTemplate>
private void ListView_Scrolled(object sender, ScrolledEventArgs e)
{
   var rowHeight = MyListView.RowHeight;  // you need to set it in xaml in advance , otherwise it will always -1 .If you bind the height in code behind , use the height instead of it

   double contentHeight = rowHeight * MyItems.Count;  // content height of listview

   double positionY = e.ScrollY;

   // if(...) handle your logic 
}