Side project
Pokédex Pro
A Pokédex desktop app in C# and WPF that loads its data live from the PokéAPI, with clean layering between UI, logic and data.
More in the privacy policy.
01
C# & WPF development
- Built a Pokédex desktop application with WPF (C#).
- Fetches data through a generic method with error handling.
- Loads the Japanese name from the species endpoint.
- Calculates base stats; the model is prepared for IVs, EVs and natures.
- Scrollable ID selector for quick navigation.
- Uses the high-quality sprites of the PokéAPI.
- Separate layers for UI, logic and data parsing for easy maintenance.
public async Task<T?> Fetch<T>(string endpoint, CancellationToken cancellationToken = default) where T : class
{
try
{
HttpResponseMessage response = await _client.GetAsync(endpoint, cancellationToken);
if (response.StatusCode == HttpStatusCode.NotFound)
return null;
response.EnsureSuccessStatusCode();
string jsonResponse = await response.Content.ReadAsStringAsync(cancellationToken);
return JsonSerializer.Deserialize<T>(jsonResponse);
}
catch (HttpRequestException ex)
{
Console.Error.WriteLine($"HTTP fetching error: {ex.Message}");
return null;
}
catch (JsonException ex)
{
Console.Error.WriteLine($"JSON parsing error: {ex.Message}");
return null;
}
}
public async Task<Pokemon?> GetPokemonAsync(string idOrName, CancellationToken cancellationToken = default) =>
await Fetch<Pokemon>($"pokemon/{idOrName}", cancellationToken);
public async Task<Ability?> GetAbilityAsync(string idOrName, CancellationToken cancellationToken = default) =>
await Fetch<Ability>($"ability/{idOrName}", cancellationToken);
public async Task<Move?> GetMoveAsync(string idOrName, CancellationToken cancellationToken = default) =>
await Fetch<Move>($"move/{idOrName}", cancellationToken);
public async Task<SpeciesDetails?> GetLocalizedNamesAsync(string idOrName, CancellationToken cancellationToken = default) =>
await Fetch<SpeciesDetails>($"pokemon-species/{idOrName}", cancellationToken);02
View model & stats
- Asynchronous view model with busy and error state.
- Base stats are mapped from the API response into a typed record.
private async Task LoadAsync(CancellationToken ct)
{
try
{
IsBusy = true;
Error = null;
Pokemon = await _api.GetPokemonAsync(Query, ct);
if (Pokemon is null) { Artwork = null; JapaneseName = null; return; }
Artwork = Pokemon.Sprites?.Other?.OfficialArtwork?.FrontDefault ?? Pokemon.Sprites?.FrontDefault;
var species = await _api.GetLocalizedNamesAsync(Pokemon.Name, ct);
JapaneseName = species?.Names?.FirstOrDefault(n => n.Language.Name.Equals("ja-Hrkt", StringComparison.OrdinalIgnoreCase))?.Name ?? species?.Names?.FirstOrDefault(n => n.Language.Name.Equals("ja", StringComparison.OrdinalIgnoreCase))?.Name;
}
catch (Exception ex)
{
Error = ex.Message;
}
finally
{
IsBusy = false;
}
}
public static BaseStats GetBaseStats(Pokemon pokemon)
{
ArgumentNullException.ThrowIfNull(pokemon);
if (pokemon.Stats is null || pokemon.Stats.Count == 0)
throw new InvalidOperationException("There are no valid stat entries");
Dictionary<string, int> dict = pokemon.Stats.ToDictionary(s => s.StatValue.Name, s =>
(int)s.BaseStat, StringComparer.OrdinalIgnoreCase);
int Get(string key) => dict.TryGetValue(key, out var v) ? v :
throw new KeyNotFoundException($"stat entry '{key}' in '{pokemon.Name}' was not found.");
return new BaseStats(
HP: Get("hp"),
Attack: Get("attack"),
Defense: Get("defense"),
SpAttack: Get("special-attack"),
SpDefense: Get("special-defense"),
Speed: Get("speed")
);
}Interested in working together?