首页 > 解决方案 > 如何在滚动视图 [Xamarin.Forms] 中获取当前可见项目?

问题描述

我有一个自定义控件作为滚动视图,我想扩展它,想知道我们何时处于某个项目。

public class ExtendedScrollView : ScrollView
{
    public ExtendedScrollView()
    {
        this.Scrolled += ExtendedScrollView_Scrolled;
    }

    private void ExtendedScrollView_Scrolled(object sender, ScrolledEventArgs e)
    {
        double scrollingSpace = this.ContentSize.Height - this.Height;

        if (scrollingSpace <= e.ScrollY)
        {
            // Hits bottom
        }
    }
}

我已成功找到底部,但我如何计算以查看当前可见的滚动视图中的当前视图(或视图)?

 <controls:ExtendedScrollView>
       <StackLayout BindableLayout.ItemsSource="{Binding service.MyList}">
             <BindableLayout.ItemTemplate>
                 <DataTemplate>
                       <StackLayout>

                              <controls:CustomControl Data ="{Binding .}" />

                              <BoxView HeightRequest="1"/>

                       </StackLayout>
                  </DataTemplate>
            </BindableLayout.ItemTemplate>
      </StackLayout>
 </controls:ExtendedScrollView>

这就是我成功将我的项目绑定到此滚动视图的方式。我更喜欢使用滚动视图,因为我对 ListView 有奇怪的问题,当我向下/向上滚动时它会卡住。

标签: c#xamarinxamarin.formsxamarin.androidxamarin.ios

解决方案


推荐阅读