//adds or removes a tag from one or more instruments private async void SetTag_ItemClick(object sender, RoutedEventArgs routedEventArgs) { var selectedInstruments = InstrumentsGrid.SelectedItems; var btn = (MenuItem)routedEventArgs.Source; int tagID = (int)btn.Tag; var tagResponse = await _client.GetTags().ConfigureAwait(true); if (!tagResponse.WasSuccessful) { await this.ShowMessageAsync("Error", string.Join("\n", tagResponse.Errors)).ConfigureAwait(true); return; } var tag = tagResponse.Result.FirstOrDefault(x => x.ID == tagID); if (tag == null) { await this.ShowMessageAsync("Error", "Could not find tag on the server").ConfigureAwait(true); return; } //one instrument selected foreach (Instrument instrument in selectedInstruments) { if (btn.IsChecked) { instrument.Tags.Add(tag); } else { instrument.Tags.Remove(tag); } await _client.UpdateInstrument(instrument).ConfigureAwait(true); } CollectionViewSource.GetDefaultView(InstrumentsGrid.ItemsSource).Refresh(); }