private void SelectPickerClassItem(DeckPickerClassItem dpci) { var heroClass = dpci.DataContext as HeroClassAll?; if (heroClass != null && !SelectedClasses.Contains(heroClass.Value)) { SelectedClasses.Add(heroClass.Value); dpci.OnSelected(); } }
private void SelectPickerClassItem(DeckPickerClassItem dpci) { #pragma warning disable IDE0019 var heroClass = dpci.DataContext as HeroClassAll?; if (heroClass != null && !SelectedClasses.Contains(heroClass.Value)) { SelectedClasses.Add(heroClass.Value); dpci.OnSelected(); } #pragma warning restore IDE0019 }
private void Selector_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { if (_reselectingClasses) { return; } var removedPickerClassItems = e.RemovedItems.OfType <DeckPickerClassItem>(); var addedPickerClassItems = e.AddedItems.OfType <DeckPickerClassItem>().ToList(); var addedClasses = PickerClassItemsAsEnum(addedPickerClassItems).ToList(); if (addedClasses.Contains(HeroClassAll.All)) { _reselectingClasses = true; var senderList = ((ListView)sender); senderList.UnselectAll(); foreach (var item in senderList.Items) { var dpci = item as DeckPickerClassItem; if (dpci != null) { var hca = (HeroClassAll)dpci.DataContext; switch (hca) { case HeroClassAll.All: senderList.SelectedItems.Add(item); SelectPickerClassItem(dpci); break; case HeroClassAll.Archived: if (!SelectedClasses.Contains(HeroClassAll.Archived)) { if (addedClasses.Contains(HeroClassAll.Archived)) { senderList.SelectedItems.Add(item); SelectPickerClassItem(dpci); } } else { if (PickerClassItemsAsEnum(removedPickerClassItems).Contains(HeroClassAll.Archived)) { DeselectPickerClassItem(dpci); } else { senderList.SelectedItems.Add(item); } } break; default: DeselectPickerClassItem(dpci); break; } } } _reselectingClasses = false; } else { DeckPickerClassItem removedAllClassItem = null; foreach (var dpci in removedPickerClassItems) { var heroClass = dpci.DataContext as HeroClassAll?; switch (heroClass) { case null: continue; case HeroClassAll.All: // We remove this from SelectedClasses now but we don't raise it's OnDeselected event yet, // instead store a reference to it in case we want to quietly add this back to the // SelectedClasses list later SelectedClasses.Remove(heroClass.Value); removedAllClassItem = dpci; break; default: DeselectPickerClassItem(dpci); break; } } var allIsSelected = SelectedClasses.Contains(HeroClassAll.All); foreach (var dpci in addedPickerClassItems) { var heroClass = dpci.DataContext as HeroClassAll?; if (heroClass == null) { continue; } if (allIsSelected && heroClass != HeroClassAll.Archived) { _reselectingClasses = true; ((ListView)sender).SelectedItems.Remove(dpci); _reselectingClasses = false; continue; } SelectPickerClassItem(dpci); } if (SelectedClasses.Count == 0 && !_clearingClasses) { var senderList = (ListView)sender; if (removedAllClassItem == null) { var dpciAll = PickerClassItemFromEnum(senderList, HeroClassAll.All); // Select 'All', raising its OnSelected event _reselectingClasses = true; senderList.SelectedItems.Add(dpciAll); SelectPickerClassItem(dpciAll); _reselectingClasses = false; } else { // If there are no selected classes, and we earlier removed 'All', quietly add it back _reselectingClasses = true; senderList.SelectedItems.Add(removedAllClassItem); SelectedClasses.Add(HeroClassAll.All); _reselectingClasses = false; // And make sure we do not raise its OnDeselected event if we were going to removedAllClassItem = null; } } // If we removed the 'All' class earlier, raise the DeckPickerClassItem's OnDeselected event now removedAllClassItem?.OnDelselected(); } if (Core.MainWindow.IsLoaded) { UpdateDecks(); } }