Reputation: 1
Here is a ContentPage
with a SearchBar
and a ListView
.
ListView
is updating as the user type in the SearchBar
.
<StackLayout>
<SearchBar Placeholder="Rechercher..." TextChanged="..." x:Name="searchBar"/>
<ListView ItemTapped="..." HasUnevenRows="True" SelectionMode="None" x:Name="ListView_Abonnes"
ItemsSource="..." ItemTemplate="..." Refreshing="..." IsPullToRefreshEnabled="True">
</StackLayout>
The problem is that when the user scoll the ListView results, the keyboard does not close automatically. Please, somebody know how to do if we want that the keyboard close when user scoll the ListView ?
Thanks you
I already try to catch gesture recognizer on the StackLayout
, and I also try to catch the scrolled event on the ListView
, but that has no effect because the ListView
scrolled() event is called when updated.
Upvotes: 0
Views: 1819
Reputation: 10078
You can call the Scrolled event and then hide the Soft Input Keyboard if it is currently visible using Maui Community toolkit.
Here's the code snippet for your reference:
XMAL:
<StackLayout>
<SearchBar Placeholder="Rechercher..." TextChanged="SearchBar_TextChanged" x:Name="searchBar"/>
<ListView x:Name="ListView_Abonnes" HasUnevenRows="True" SelectionMode="None" IsPullToRefreshEnabled="True" Refreshing="ListView_Refreshing" Scrolled="ListView_Abonnes_Scrolled">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{Binding Name}" >
</TextCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
Code-behind:
private void ListView_Abonnes_Scrolled(object sender, ScrolledEventArgs e)
{
searchBar.HideKeyboardAsync(CancellationToken.None);
}
Upvotes: 3