private void MyGroupManager_GroupsChanged(StaticGroupManager sender, GroupManagerEventArgs e) { if (e.eventOperation == GroupManagerEventOperation.Add) { e.operationItem.NameChanged += MyGroupManager_ChampionList_NameChanged; } DisplayGroups(); }
private void _groupManager_GroupsChanged(StaticGroupManager sender, GroupManagerEventArgs e) { if (sender != null) { //Try to preserve checked checkboxes switch (e.eventOperation) { case GroupManagerEventOperation.Add: //Get index of new added item int newItemIndex = _gm.indexOf(e.operationItem.getName()); //Insert item here at the correct spot System.Windows.Controls.CheckBox chk = new System.Windows.Controls.CheckBox(); chk.Content = e.operationItem.getName(); chk.Checked += new RoutedEventHandler(CheckBox_CheckStateChanged); cboGroups.Items.Insert(newItemIndex, chk); break; case GroupManagerEventOperation.Remove: //Remove it here based on e known name for (int i = 0; i < cboGroups.Items.Count; i++) { CheckBox cb = (CheckBox)cboGroups.Items[i]; if (cb.Content.ToString() == e.operationItem.getName()) { cboGroups.Items.RemoveAt(i); break; } } break; case GroupManagerEventOperation.Reposition: //Reposition it here based on name //Get new position int newPosition = _gm.indexOf(e.operationItem.getName()); int oldPosition = -1; bool isChecked = false; //Find old position for (int i = 0; i < cboGroups.Items.Count; i++) { CheckBox cb = (CheckBox)cboGroups.Items[i]; if (cb.Content.ToString() == e.operationItem.getName()) { oldPosition = i; isChecked = cb.IsChecked.Value; cboGroups.Items.RemoveAt(i); break; } } //Make new checkbox at that index System.Windows.Controls.CheckBox chkReplace = new System.Windows.Controls.CheckBox(); chkReplace.Content = e.operationItem.getName(); chkReplace.IsChecked = isChecked; chkReplace.Checked += new RoutedEventHandler(CheckBox_CheckStateChanged); cboGroups.Items.Insert(newPosition, chkReplace); break; } cboGroups.UpdateLayout(); } }