Skip to content

Instantly share code, notes, and snippets.

@icebeam7
Created July 7, 2019 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icebeam7/6777de7d6fe88cbf32cd6a67927d6710 to your computer and use it in GitHub Desktop.
Save icebeam7/6777de7d6fe88cbf32cd6a67927d6710 to your computer and use it in GitHub Desktop.
Search and Scroll navigation example (cs code)
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