private void LoadTag() { TagDisplay.Children.Clear(); foreach (var item in todo.TagItems) { PreviewTag previewTag = new PreviewTag(item); previewTag.tagItem = item; previewTag.RemovePreTag += new EventHandler(this.RemovePreTag); TagDisplay.Children.Add(previewTag); } }
//Load in the current item's tags private void LoadTagItems() { if (todo.TagItems != null) { foreach (var item in todo.TagItems) { PreviewTag tag = new PreviewTag(item); tag.RemovePreTag += new EventHandler(this.RemovePreTag); TagDisplay.Children.Add(tag); } } }
private void RemovePreTag(object sender, EventArgs e) { PreviewTag tag = sender as PreviewTag; todo.TagItems.RemoveAt(todo.TagItems.FindIndex(x => x.ID == tag.tagItem.ID)); UpdateChosenTag?.Invoke(itembar, EventArgs.Empty); LoadTag(); itembar.LoadTagItems(); LoadAvailableTagItemsChoices(); }
//Due to itembar.TagItem or Todo.TagItems didn't //get a actual data(get;set;) so it cannot use "Add" or //"itembar.TagItems[x] = TagItem[y]" // I guseed you already knew it but I still want to make a note private void TagComBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (TagItemCombobox.SelectedItem.GetType().Name == "PreviewTag") { //MessageBox.Show(TagItemCombobox.SelectedItem.GetType().Name); PreviewTag tag = TagItemCombobox.SelectedItem as PreviewTag; TagItem tagItem = tag.tagItem; todo.TagItems.Add(tagItem); LoadTag(); TagItemCombobox.SelectedIndex = 0; TagItemCombobox.Items.Remove(tag); } itembar.LoadTagItems(); }