Created
July 29, 2019 06:04
-
-
Save AlejandroRuiz/7483c77fd78e6bcf8982ab6032c69263 to your computer and use it in GitHub Desktop.
Xamarin Forms Custom SearchHandler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GPlayMusicSearchHandler : SearchHandler | |
{ | |
public GPlayMusicSearchHandler() | |
{ | |
} | |
protected override void OnQueryChanged(string oldValue, string newValue) | |
{ | |
base.OnQueryChanged(oldValue, newValue); | |
if (string.IsNullOrWhiteSpace(newValue)) | |
{ | |
ItemsSource = Artists.OrderBy(item => item.Name); | |
} | |
else | |
{ | |
ItemsSource = Artists.Where(item => item.Name.ToLower().Contains(newValue.ToLower())).OrderBy(item => item.Name).ToList<Artist>(); | |
} | |
} | |
protected override void OnItemSelected(object item) | |
{ | |
base.OnItemSelected(item); | |
//YOUR LOGIC | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ContentPage> | |
<Shell.SearchHandler> | |
<services:GPlayMusicSearchHandler Placeholder="Search music" | |
ShowsResults="true" | |
SearchBoxVisibility="Collapsible" | |
CancelButtonColor="Black" | |
TextColor="Black" | |
DisplayMemberName="Name"> | |
<services:GPlayMusicSearchHandler.ItemTemplate> | |
<DataTemplate> | |
<views:ArtistSearchItemView /> | |
</DataTemplate> | |
</services:GPlayMusicSearchHandler.ItemTemplate> | |
</services:GPlayMusicSearchHandler> | |
</Shell.SearchHandler> | |
<ContentPage.Content> | |
</ContentPage.Content> | |
</ContentPage> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment