コード例 #1
0
        /// <summary>
        /// Removes a tag from the collection
        /// </summary>
        internal void RemoveTag(TokenizedTagItem tag, bool cancelEvent = false)
        {
            if (this.ItemsSource != null)
            {
                ((IList)this.ItemsSource).Remove(tag); // assume IList for convenience
                this.Items.Refresh();
                //UpdateAllTagsProperty();

                if (TagRemoved != null && !cancelEvent)
                {
                    TagRemoved(this, new TokenizedTagEventArgs(tag));
                }

                // select the last item
                if (this.SelectedItem == null && this.Items.Count > 0)
                {
                    //TokenizedTagItem itemToSelect = this.Items.GetItemAt(0) as TokenizedTagItem;
                    TokenizedTagItem itemToSelect = Items.GetItemAt(Items.Count - 1) as TokenizedTagItem;
                    if (!object.ReferenceEquals(itemToSelect, null))
                    {
                        RaiseTagClick(itemToSelect);
                        if (this.IsSelectable)
                        {
                            this.SelectedItem = itemToSelect;
                        }
                    }
                    //this.SelectedItem = this.Items.CurrentItem;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Adds a tag to the collection
        /// </summary>
        internal void AddTag(TokenizedTagItem tag)
        {
            TokenizedTagItem itemToSelect = null;

            if (this.SelectedItem == null && this.Items.Count > 0)
            {
                itemToSelect = (TokenizedTagItem)this.SelectedItem;
            }
            ((IList)this.ItemsSource).Add(tag); // assume IList for convenience
            this.Items.Refresh();

            // select the previous item
            if (!object.ReferenceEquals(itemToSelect, null))
            {
                // && !object.ReferenceEquals(TagApplied, null)
                //TagApplied.Invoke(this, new TokenizedTagEventArgs(appliedTag));
                RaiseTagClick(itemToSelect);
                if (this.IsSelectable)
                {
                    this.SelectedItem = itemToSelect;
                }
            }

            // update values
            //UpdateAllTagsProperty();
            TagAdded?.Invoke(this, new TokenizedTagEventArgs(tag));
        }
コード例 #3
0
        /// <summary>
        /// Raises the TagDoubleClick event
        /// </summary>
        internal void RaiseTagDoubleClick(TokenizedTagItem tag)
        {
            //if (this.IsSelectable)
            //    this.SelectedItem = tag;

            UpdateAllTagsProperty();
            tag.IsEditing = true;
        }
コード例 #4
0
 /// <summary>
 /// Raises the TagClick event
 /// </summary>
 internal void RaiseTagApplied(TokenizedTagItem tag)
 {
     /*
      * if (this.IsSelectable)
      *  this.SelectedItem = tag;
      */
     TagApplied?.Invoke(this, new TokenizedTagEventArgs(tag));
 }
コード例 #5
0
 /// <summary>
 /// Raises the TagClick event
 /// </summary>
 internal void RaiseTagApplied(TokenizedTagItem tag)
 {
     /*
      * if (this.IsSelectable)
      *  this.SelectedItem = tag;
      */
     if (this.TagApplied != null)
     {
         TagApplied(this, new TokenizedTagEventArgs(tag));
     }
 }
コード例 #6
0
        internal TokenizedTagItem InitializeNewTag(bool suppressEditing = false)
        {
            var newItem = new TokenizedTagItem()
            {
                IsEditing = !suppressEditing
            };

            AddTag(newItem);
            UpdateAllTagsProperty();
            this.IsEditing = !suppressEditing;

            return(newItem);
        }
コード例 #7
0
        public void OnApplyTemplate(TokenizedTagItem appliedTag = null)
        {
            Button createBtn = this.GetTemplateChild("PART_CreateTagButton") as Button;

            if (createBtn != null)
            {
                createBtn.Click -= createBtn_Click;
                createBtn.Click += createBtn_Click;
                //createBtn.Focus();
                // nixin - focuses
                //createBtn_Click(createBtn, null);
            }

            base.OnApplyTemplate();

            if (appliedTag != null && !object.ReferenceEquals(TagApplied, null))
            {
                TagApplied.Invoke(this, new TokenizedTagEventArgs(appliedTag));
            }
        }
コード例 #8
0
        void TokenizedTagControl_LostKeyboardFocus(object sender, System.Windows.Input.KeyboardFocusChangedEventArgs e)
        {
            if (!IsSelectable)
            {
                this.SelectedItem = null;
                return;
            }

            TokenizedTagItem itemToSelect = null;

            if (this.Items.Count > 0 && !object.ReferenceEquals((TokenizedTagItem)this.Items.CurrentItem, null))
            {
                if (this.SelectedItem != null && ((TokenizedTagItem)this.SelectedItem).Text != null &&
                    !((TokenizedTagItem)this.SelectedItem).IsEditing)
                {
                    itemToSelect = (TokenizedTagItem)this.SelectedItem;
                }
                else if (!String.IsNullOrWhiteSpace(((TokenizedTagItem)this.Items.CurrentItem).Text))
                {
                    itemToSelect = (TokenizedTagItem)this.Items.CurrentItem;
                }
            }

            // select the previous item
            if (!object.ReferenceEquals(itemToSelect, null))
            {
                e.Handled = true;
                RaiseTagApplied(itemToSelect);
                if (this.IsSelectable)
                {
                    this.SelectedItem = itemToSelect;
                    //itemToSelect.Focus();
                }
            }
            //RaiseTagClick(itemToSelect);
        }
コード例 #9
0
 public TokenizedTagEventArgs(TokenizedTagItem item)
 {
     this.Item = item;
 }