コード例 #1
0
ファイル: TagControl.cs プロジェクト: forki/WPFTagControl
        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);
            }
        }
コード例 #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));
 }
コード例 #3
0
        internal void AddTag(TagItem tag)
        {
            if (ItemsSource == null)
            {
                ItemsSource = new List <TagItem>();
            }

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

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

            var its = Tags;

            if (its is IList)
            {
                ((IList)its).Remove(removedTag.Value);
            }
        }
コード例 #7
0
ファイル: TagControl.cs プロジェクト: forki/WPFTagControl
 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));
     }
 }
コード例 #8
0
 internal void RaiseTagDoubleClick(TagItem tag)
 {
     tag.IsEditing = true;
 }
コード例 #9
0
 internal void RaiseTagAdded(TagItem tag)
 {
     UpdateSelectedTagsOnAdd(tag);
     Debug.WriteLine($"RaiseTagAdded: {tag.Text}");
     TagAdded?.Invoke(this, new TagEventArgs(tag));
 }
コード例 #10
0
 internal void RaiseTagClick(TagItem tag)
 {
     TagClick?.Invoke(this, new TagEventArgs(tag));
 }
コード例 #11
0
 private void RaiseTagRemoved(TagItem tag)
 {
     UpdateSelectedTagsOnRemove(tag);
     Debug.WriteLine($"RaiseTagRemoved: {tag.Text}");
     TagRemoved?.Invoke(this, new TagEventArgs(tag));
 }
コード例 #12
0
 public void RaiseTagEdited(TagItem tag)
 {
     UpdateSelectedTagsOnEdit();
     Debug.WriteLine($"RaiseTagEdited: {tag.Text}");
     TagEdited?.Invoke(this, new TagEventArgs(tag));
 }
コード例 #13
0
 public TagEventArgs(TagItem item)
 {
     this.Item = item;
 }