Created
July 7, 2019 18:40
-
-
Save icebeam7/6777de7d6fe88cbf32cd6a67927d6710 to your computer and use it in GitHub Desktop.
Search and Scroll navigation example (cs code)
This file contains 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
using System; | |
using Xamarin.Forms; | |
using Xamarin.Forms.Xaml; | |
using Pokedex_XamUIJuly.ViewModels; | |
namespace Pokedex_XamUIJuly.Views | |
{ | |
[XamlCompilation(XamlCompilationOptions.Compile)] | |
public partial class _03_SearchScroll : ContentPage | |
{ | |
PokemonViewModel vm; | |
public _03_SearchScroll() | |
{ | |
InitializeComponent(); | |
vm = new PokemonViewModel(); | |
BindingContext = vm; | |
} | |
protected async override void OnAppearing() | |
{ | |
base.OnAppearing(); | |
await vm.LoadPokedex(); | |
} | |
private void SearchBar_SearchButtonPressed(object sender, EventArgs e) | |
{ | |
var pokemon = searchBar.Text; | |
var result = vm.SearchScrollPokemon(pokemon); | |
if (result != null) | |
{ | |
collectionView.ScrollTo(result, animate: false, position: ScrollToPosition.Center); | |
collectionView.SelectedItem = result; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment