//Remove staff from project when user click delete button of the chip private void StaffChip_DeleteClick(object sender, RoutedEventArgs e) { TwoTagsChip chip = (TwoTagsChip)sender; Staff t = (Staff)chip.Tag; bool canRemove = IsDeletable(t.Key); if (!canRemove) { return; } ToggleButton btn = (ToggleButton)chip.Tag2; btn.IsChecked = false; RemoveStaffChip(chip); }
//Remove the chips from the wrappanel private void RemoveStaffChip(TwoTagsChip chip) { var User = (Staff)chip.Tag; foreach (Staff item in this.SelectedStaff) { if (item.Key == User.Key) { this.SelectedStaff.Remove(item); break; } } foreach (ComboBoxItem item in this.ProjectOwner_Combobox.Items) { if (((Staff)item.Tag).Key == User.Key) { this.ProjectOwner_Combobox.Items.Remove(item); break; } } this.SelectedStaffsWrapPanel.Children.Remove(chip); }
//Select staff private void StaffSelected(object sender, RoutedEventArgs e) { try { //User can only select staff by check a toggle button ToggleButton btn = (ToggleButton)sender; //Get the staff instance string staffkey = btn.Tag.ToString(); var User = this.StaffDbset.Local.Where(st => st.Key == staffkey).FirstOrDefault(); //Allow to be select as project owner bool _CItemExist = false; foreach (ComboBoxItem _item in this.ProjectOwner_Combobox.Items) { Staff _staff = (Staff)_item.Tag; if (_staff.Key == User.Key) { _CItemExist = true; break; } } if (!_CItemExist) { ComboBoxItem _CItem = new ComboBoxItem(); _CItem.Content = User.Surname + " " + User.Firstname; _CItem.Tag = User; this.ProjectOwner_Combobox.Items.Add(_CItem); } //if found if (User != null) { //Create the list of selected staffs and attach this list to ProjectOwner_Combobox if (this.SelectedStaff == null) { this.SelectedStaff = new List <Staff>(); } //Add user to selected list this.SelectedStaff.Add(User); //Create the chip and add to wrap panel TwoTagsChip chip = new TwoTagsChip(); chip.Margin = new Thickness(3); chip.Icon = btn.Content; chip.Tag = User; chip.Tag2 = btn; chip.Content = User.Firstname; chip.ToolTip = User.Surname + " " + User.Firstname; chip.IsDeletable = true; chip.DeleteClick += StaffChip_DeleteClick; this.SelectedStaffsWrapPanel.Children.Add(chip); } else { this.MySnackbar.MessageQueue.Enqueue("UNABLE TO SELECT USER"); } } catch (Exception ex) { this.MySnackbar.MessageQueue.Enqueue("UNABLE TO SELECT USER"); Console.WriteLine(ex.Message); } }