private async void OnCachePinClick(object sender, MouseButtonEventArgs args) { if (activePinPerson == null) { return; } var pin = sender as Pushpin; Geocache cachePinCache = (Geocache)(pin.Tag as Dictionary <string, ITag>)["Geocache"]; // To prevent the calling of OnMapLeftClick. args.Handled = true; if (pin.Background == colors["Red"]) { try { await _db.AddFoundGeocacheAsync(new FoundGeocache { PersonID = activePinPerson.ID, GeocacheID = cachePinCache.ID }); pin.Background = colors["Green"]; } catch (Exception e) { MessageBox.Show("Something went wrong when updating the database.\r\n\r\n" + e.Message, "Error"); } } else if (pin.Background == colors["Green"]) { try { await _db.RemoveFoundGeocacheAsync(activePinPerson, cachePinCache); pin.Background = colors["Red"]; } catch (Exception e) { MessageBox.Show("Something went wrong when updating the database.\r\n\r\n" + e.Message, "Error"); } } }