private void OnMainComboBoxSelectionChanged(object sender, SelectionChangedEventArgs e) { var selected = e.AddedItems[0] as ComboItem; RefreshMainComboListItem(selected); SubComboBox.SelectedIndex = 0; RefreshSubComboListItem(ComboItem.All); ListView.Dispatcher.Invoke(new Action(() => ListView.Items.Refresh())); SubComboList.Clear(); SubComboList.Add(ComboItem.All); if (!selected.IsSpecial) { var subcategory = (selected.Value as L4D2Type.Category).Children; if (subcategory != null && subcategory.Count > 0) { foreach (var v in subcategory) { SubComboList.Add(new ComboItem(v, v)); } SubComboList.Add(ComboItem.Uncategorized); SubComboList.Add(ComboItem.IgnoreList); SubComboList.Add(ComboItem.Conflicted); } } SubComboBox.Items.Refresh(); }
private void LoadComboItem() { MainComboList.Clear(); MainComboList.Add(ComboItem.All); foreach (var v in L4D2Type.GetCategory()) { MainComboList.Add(new ComboItem(v, v)); } MainComboList.Add(ComboItem.Uncategorized); MainComboList.Add(ComboItem.IgnoreList); MainComboList.Add(ComboItem.Conflicted); SubComboList.Clear(); SubComboList.Add(ComboItem.All); MainComboBox.SelectedIndex = 0; SubComboBox.SelectedIndex = 0; MainComboBox.Items.Refresh(); SubComboBox.Items.Refresh(); }
public void Refresh() { object selectedItemMain = null; object selectedItemSub = null; var selectedMain = MainComboBox.SelectedItem as ComboItem; if (selectedMain != null) { selectedItemMain = selectedMain.Category; var selectedSub = SubComboBox.SelectedItem as ComboItem; if (selectedSub != null) { selectedItemSub = selectedSub.Category; } } LoadComboItem(); Func <ComboBox, object, ComboItem> FindCategoryInItem = (combo, category) => { foreach (var item in combo.Items) { if (item is ComboItem) { if ((item as ComboItem).Category == category) { return(item as ComboItem); } } } return(null); }; if (selectedItemMain != null) { var findMain = FindCategoryInItem(MainComboBox, selectedItemMain); if (findMain != null) { MainComboBox.SelectedItem = findMain; SubComboList.Clear(); SubComboList.Add(ComboItem.All); if (!findMain.IsSpecial) { var subcategory = (findMain.Category as L4D2Type.Category).Children; if (subcategory != null && subcategory.Count > 0) { foreach (var v in subcategory) { SubComboList.Add(new ComboItem(v, v)); } SubComboList.Add(ComboItem.Uncategorized); SubComboList.Add(ComboItem.IgnoreList); SubComboList.Add(ComboItem.Conflicted); } } if (selectedItemSub != null) { var findSub = FindCategoryInItem(SubComboBox, selectedItemSub); if (findSub != null) { SubComboBox.SelectedItem = findSub; } } } } MainComboBox.Items.Refresh(); SubComboBox.Items.Refresh(); }