Ejemplo n.º 1
0
        public async Task <PokemonList> GetPokemonList(string Url)
        {
            using (HttpClient client = new HttpClient())
            {
                using (HttpResponseMessage response = await client.GetAsync(Url))
                {
                    using (HttpContent content = response.Content)
                    {
                        var data = await content.ReadAsStringAsync();

                        PokemonList pokemonList = JsonConvert.DeserializeObject <PokemonList>(data);

                        return(pokemonList);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public MainWindow()
        {
            InitializeComponent();
            string baseUrl = "https://pokeapi.co/api/v2/pokemon?limit=100";


            try
            {
                pokemonList = Task.Run(() => GetPokemonList(baseUrl)).Result;
                buttons     = new ObservableCollection <PokemonButton>();
                foreach (NameAndUrl pokemon in pokemonList.results)
                {
                    buttons.Add(new PokemonButton {
                        ButtonContent = char.ToUpper(pokemon.name[0]) + pokemon.name.Substring(1), Url = pokemon.url
                    });
                }

                ic.ItemsSource = buttons;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }