public void ApplyTemplate(TagItem appliedTag = null, bool cancelEvent = false) { var createBtn = GetTemplateChild("PART_CreateTagButton") as Button; if (createBtn != null) { createBtn.Click -= createBtn_Click; createBtn.Click += createBtn_Click; } var tagIcon = GetTemplateChild("PART_TagIcon") as Path; if (tagIcon != null) { tagIcon.MouseUp -= createBtn_Click; tagIcon.MouseUp += createBtn_Click; } base.OnApplyTemplate(); if (appliedTag != null && !cancelEvent) { RaiseTagAdded(appliedTag); } }
private void UpdateSelectedTagsOnAdd(TagItem addedTag) { var source = (IList <TagItem>)ItemsSource; //if (source.Count == SelectedTags.Count) //Update SelectedTags list if user edits tags // SelectedTags.Where(i => source.All(s => !s.Text.Equals(i) || i.Equals(addedTag.Text))) // .ToList() // .ForEach(r => SelectedTags.Remove(r)); // SelectedTags.Add(((TagObject)addedTag.Value)); }
internal void AddTag(TagItem tag) { if (ItemsSource == null) { ItemsSource = new List <TagItem>(); } ((IList)ItemsSource).Add(tag); // assume IList for convenience Items.Refresh(); }
internal TagItem InitializeNewTag(bool suppressEditing = false) { var newItem = new TagItem { IsEditing = !suppressEditing }; AddTag(newItem); IsEditing = !suppressEditing; return(newItem); }
internal void RemoveTag(TagItem tag, bool cancelEvent = false) { if (ItemsSource != null) { ((IList)ItemsSource).Remove(tag); // assume IList for convenience Items.Refresh(); if (!cancelEvent) { RaiseTagRemoved(tag); } } }
private void UpdateSelectedTagsOnRemove(TagItem removedTag) { if (removedTag == null) { return; } var its = Tags; if (its is IList) { ((IList)its).Remove(removedTag.Value); } }
private void UpdateSelectedTagsOnRemove(TagItem removedTag) { if (removedTag == null) { return; } if (!string.IsNullOrEmpty(removedTag.Text)) // Remove if delete button was clicked { SelectedTags.Remove(removedTag.Text); } else // Remove if backspace was used to delete tag (TagItem Text was changed to empty and was then removed) { var source = (IList <TagItem>)ItemsSource; SelectedTags.Where(i => source.All(s => !s.Text.Equals(i))) .ToList() .ForEach(r => SelectedTags.Remove(r)); } }
internal void RaiseTagDoubleClick(TagItem tag) { tag.IsEditing = true; }
internal void RaiseTagAdded(TagItem tag) { UpdateSelectedTagsOnAdd(tag); Debug.WriteLine($"RaiseTagAdded: {tag.Text}"); TagAdded?.Invoke(this, new TagEventArgs(tag)); }
internal void RaiseTagClick(TagItem tag) { TagClick?.Invoke(this, new TagEventArgs(tag)); }
private void RaiseTagRemoved(TagItem tag) { UpdateSelectedTagsOnRemove(tag); Debug.WriteLine($"RaiseTagRemoved: {tag.Text}"); TagRemoved?.Invoke(this, new TagEventArgs(tag)); }
public void RaiseTagEdited(TagItem tag) { UpdateSelectedTagsOnEdit(); Debug.WriteLine($"RaiseTagEdited: {tag.Text}"); TagEdited?.Invoke(this, new TagEventArgs(tag)); }
public TagEventArgs(TagItem item) { this.Item = item; }