Поделиться через


Быстрая прокрутка ListView в Android

Этот многоплатформенный пользовательский интерфейс приложений .NET (.NET MAUI) для платформы Android используется для быстрого прокрутки данных в ListView. Он используется в XAML, задав ListView.IsFastScrollEnabled присоединенное свойство значением boolean :

<ContentPage ...
             xmlns:android="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific;assembly=Microsoft.Maui.Controls"
             xmlns:local="clr-namespace:PlatformSpecifics"
             x:DataType="local:ListViewViewModel">
    <StackLayout>
        ...
        <ListView ItemsSource="{Binding GroupedEmployees}"
                  GroupDisplayBinding="{Binding Key}"
                  IsGroupingEnabled="true"
                  android:ListView.IsFastScrollEnabled="true">
            ...
        </ListView>
    </StackLayout>
</ContentPage>

Кроме того, его можно использовать из C# с помощью api fluent:

using Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific;
...

var listView = new Microsoft.Maui.Controls.ListView { IsGroupingEnabled = true, ItemTemplate = personDataTemplate };
listView.SetBinding(ItemsView<Cell>.ItemsSourceProperty, static (ListViewViewModel vm) => vm.GroupedEmployees); // .NET 9+ compiled binding
listView.GroupDisplayBinding = Binding.Create(static (Grouping<char, Person> g) => g.Key); // .NET 9+ compiled binding
listView.On<Microsoft.Maui.Controls.PlatformConfiguration.Android>().SetIsFastScrollEnabled(true);

Метод ListView.On<Microsoft.Maui.Controls.PlatformConfiguration.Android> указывает, что эта платформа будет работать только в Android. Метод ListView.SetIsFastScrollEnabled в Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific пространстве имен используется для быстрого прокрутки данных в пространстве ListViewимен. Кроме того, SetIsFastScrollEnabled метод можно использовать для переключения быстрой прокрутки путем вызова IsFastScrollEnabled метода, чтобы вернуть, включена ли быстрая прокрутка:

listView.On<Microsoft.Maui.Controls.PlatformConfiguration.Android>().SetIsFastScrollEnabled(!listView.On<Microsoft.Maui.Controls.PlatformConfiguration.Android>().IsFastScrollEnabled());

Результатом является то, что быстрая прокрутка данных в ней ListView может быть включена, что изменяет размер отпечатка прокрутки:

ListView FastScroll Platform-Specific.