【问题标题】:Xamarin CollectionView Current GroupXamarin CollectionView 当前组
【发布时间】:2021-07-24 14:24:59
【问题描述】:

滚动时如何在 CollectionView 中获取当前可见的组名? 我想在页面标题中显示此信息。

myCollectionView.Scrolled += (object sender, ItemsViewScrolledEventArgs e) =>
{
    int first_index = e.FirstVisibleItemIndex;
};

【问题讨论】:

  • 最简单的解决方案是让每个项目都包含一个带有组名的属性。否则,您将不得不做一些事情like this

标签: xamarin xamarin.forms xamarin.android xamarin.ios collectionview


【解决方案1】:

您可以获取索引,然后获取匹配项以获取组名。

   int first_index = e.FirstVisibleItemIndex;
        if (first_index!=0)
        {
            Name = ObservCollectionCategory[first_index-1].Category_Name;
            //The ObservCollectionCategory is the item source of Collectionview.
        }

然后绑定标题的名字。

Title="{Binding Name}"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-17
    • 1970-01-01
    • 2021-06-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多