Example #1
0
        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);
            }
        }
Example #2
0
 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));
 }
Example #3
0
        internal void AddTag(TagItem tag)
        {
            if (ItemsSource == null)
            {
                ItemsSource = new List <TagItem>();
            }

            ((IList)ItemsSource).Add(tag);  // assume IList for convenience
            Items.Refresh();
        }
Example #4
0
        internal TagItem InitializeNewTag(bool suppressEditing = false)
        {
            var newItem = new TagItem {
                IsEditing = !suppressEditing
            };

            AddTag(newItem);
            IsEditing = !suppressEditing;
            return(newItem);
        }
Example #5
0
 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);
         }
     }
 }
Example #6
0
        private void UpdateSelectedTagsOnRemove(TagItem removedTag)
        {
            if (removedTag == null)
            {
                return;
            }

            var its = Tags;

            if (its is IList)
            {
                ((IList)its).Remove(removedTag.Value);
            }
        }
Example #7
0
 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));
     }
 }
Example #8
0
 internal void RaiseTagDoubleClick(TagItem tag)
 {
     tag.IsEditing = true;
 }
Example #9
0
 internal void RaiseTagAdded(TagItem tag)
 {
     UpdateSelectedTagsOnAdd(tag);
     Debug.WriteLine($"RaiseTagAdded: {tag.Text}");
     TagAdded?.Invoke(this, new TagEventArgs(tag));
 }
Example #10
0
 internal void RaiseTagClick(TagItem tag)
 {
     TagClick?.Invoke(this, new TagEventArgs(tag));
 }
Example #11
0
 private void RaiseTagRemoved(TagItem tag)
 {
     UpdateSelectedTagsOnRemove(tag);
     Debug.WriteLine($"RaiseTagRemoved: {tag.Text}");
     TagRemoved?.Invoke(this, new TagEventArgs(tag));
 }
Example #12
0
 public void RaiseTagEdited(TagItem tag)
 {
     UpdateSelectedTagsOnEdit();
     Debug.WriteLine($"RaiseTagEdited: {tag.Text}");
     TagEdited?.Invoke(this, new TagEventArgs(tag));
 }
Example #13
0
 public TagEventArgs(TagItem item)
 {
     this.Item = item;
 }