ListView fast scrolling on Android
This .NET Multi-platform App UI (.NET MAUI) Android platform-specific is used to enable fast scrolling through data in a ListView. It's consumed in XAML by setting the ListView.IsFastScrollEnabled
attached property to a boolean
value:
<ContentPage ...
xmlns:android="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific;assembly=Microsoft.Maui.Controls">
<StackLayout>
...
<ListView ItemsSource="{Binding GroupedEmployees}"
GroupDisplayBinding="{Binding Key}"
IsGroupingEnabled="true"
android:ListView.IsFastScrollEnabled="true">
...
</ListView>
</StackLayout>
</ContentPage>
Alternatively, it can be consumed from C# using the fluent API:
using Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific;
...
var listView = new Microsoft.Maui.Controls.ListView { IsGroupingEnabled = true, ... };
listView.SetBinding(ItemsView<Cell>.ItemsSourceProperty, "GroupedEmployees");
listView.GroupDisplayBinding = new Binding("Key");
listView.On<Microsoft.Maui.Controls.PlatformConfiguration.Android>().SetIsFastScrollEnabled(true);
The ListView.On<Microsoft.Maui.Controls.PlatformConfiguration.Android>
method specifies that this platform-specific will only run on Android. The ListView.SetIsFastScrollEnabled
method, in the Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific
namespace, is used to enable fast scrolling through data in a ListView. In addition, the SetIsFastScrollEnabled
method can be used to toggle fast scrolling by calling the IsFastScrollEnabled
method to return whether fast scrolling is enabled:
listView.On<Microsoft.Maui.Controls.PlatformConfiguration.Android>().SetIsFastScrollEnabled(!listView.On<Microsoft.Maui.Controls.PlatformConfiguration.Android>().IsFastScrollEnabled());
The result is that fast scrolling through data in a ListView can be enabled, which changes the size of the scroll thumb: