private void Tc_Deleting(object sender, EventArgs e) { MyTagChips mt = (MyTagChips)sender; this.TagWrapPanel.Children.Remove(mt); this.ListOfTags.Remove(mt.MyTag); this.TagsDbset.Remove(mt.MyTag); }
private void AddTagButton_Clicked(object sender, RoutedEventArgs e) { if (this.TagsDbset == null) { this.TagsDbset = Conn.Set <Tags>(); } if (this.ListOfTags == null) { this.ListOfTags = new List <Tags>(); } //Detect if this tag is currently added to the project bool TagExist = this.ListOfTags.Where(lt => lt.TagName.ToLower() == this.NewTagTextBox.Text.ToLower().Trim()).FirstOrDefault() != null; if (TagExist) { this.AddTagPopupButton.IsPopupOpen = false; this.MySnackbar.MessageQueue.Enqueue("This tag is already added to project".ToUpper()); return; } //Create the new tag var newTag = this.TagsDbset.Create(); newTag.TagName = this.NewTagTextBox.Text; newTag.TagKey = Encryption.GetUniqueKey(16); newTag.Color = this.TagColorPicker.CurrentSelectedColor.Color.ToString(); newTag.AddedBy = ((MainWindow)App.Current.MainWindow).StaffKey; newTag.AddOn = ExtendedFunctions.GetNetworkTime(); MyTagChips tc = new MyTagChips(newTag); tc.Margin = new Thickness(3); tc.Deleting += Tc_Deleting; //Add to collections this.TagWrapPanel.Children.Add(tc); this.ListOfTags.Add(newTag); this.TagsDbset.Add(newTag); //Close the popup this.AddTagPopupButton.IsPopupOpen = false; }