/// <summary>
 ///     Raises the TagClick event
 /// </summary>
 internal void RaiseTagClick(TokenizedTagItem tag)
 {
     if (TagClick != null)
     {
         TagClick(this, new TokenizedTagEventArgs(tag));
     }
 }
 /// <summary>
 ///     Raises the TagClick event
 /// </summary>
 internal void RaiseTagApplied(TokenizedTagItem tag)
 {
     if (TagApplied != null)
     {
         TagApplied(this, new TokenizedTagEventArgs(tag));
     }
 }
        /// <summary>
        ///     Adds a tag to the collection
        /// </summary>
        internal void AddTag(TokenizedTagItem tag)
        {
            TokenizedTagItem itemToSelect = null;

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

            // select the previous item
            if (!ReferenceEquals(itemToSelect, null))
            {
                RaiseTagClick(itemToSelect);
                if (IsSelectable)
                {
                    SelectedItem = itemToSelect;
                }
            }

            if (TagAdded != null)
            {
                TagAdded(this, new TokenizedTagEventArgs(tag));
            }
        }
        /// <summary>
        ///     Removes a tag from the collection
        /// </summary>
        internal void RemoveTag(TokenizedTagItem tag, bool cancelEvent = false)
        {
            if (ItemsSource != null)
            {
                ((IList)ItemsSource).Remove(tag);                  // assume IList for convenience
                Items.Refresh();

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

                // select the last item
                if (SelectedItem == null && Items.Count > 0)
                {
                    //TokenizedTagItem itemToSelect = this.Items.GetItemAt(0) as TokenizedTagItem;
                    var itemToSelect = Items.GetItemAt(Items.Count - 1) as TokenizedTagItem;
                    if (!ReferenceEquals(itemToSelect, null))
                    {
                        RaiseTagClick(itemToSelect);
                        if (IsSelectable)
                        {
                            SelectedItem = itemToSelect;
                        }
                    }
                }
            }
        }
        private void TokenizedTagControlLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
        {
            if (!IsSelectable)
            {
                SelectedItem = null;
                return;
            }

            TokenizedTagItem itemToSelect = null;

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

            // select the previous item
            if (!ReferenceEquals(itemToSelect, null))
            {
                e.Handled = true;
                RaiseTagApplied(itemToSelect);
                if (IsSelectable)
                {
                    SelectedItem = itemToSelect;
                }
            }
        }
        internal TokenizedTagItem InitializeNewTag(bool suppressEditing = false)
        {
            var newItem = new TokenizedTagItem {
                IsEditing = !suppressEditing
            };

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

            return(newItem);
        }
        // ReSharper disable once MethodOverloadWithOptionalParameter
        public void OnApplyTemplate(TokenizedTagItem appliedTag = null)
        {
            var createBtn = GetTemplateChild("PART_CreateTagButton") as Button;

            if (createBtn != null)
            {
                createBtn.Click -= CreateBtnClick;
                createBtn.Click += CreateBtnClick;
            }

            base.OnApplyTemplate();

            if (appliedTag != null && !ReferenceEquals(TagApplied, null))
            {
                TagApplied.Invoke(this, new TokenizedTagEventArgs(appliedTag));
            }
        }
 public TokenizedTagEventArgs(TokenizedTagItem item)
 {
     Item = item;
 }
 /// <summary>
 ///     Raises the TagDoubleClick event
 /// </summary>
 internal void RaiseTagDoubleClick(TokenizedTagItem tag)
 {
     UpdateAllTagsProperty();
     tag.IsEditing = true;
 }
Esempio n. 10
0
 /// <summary>
 ///     Raises the TagClick event
 /// </summary>
 internal void RaiseTagApplied(TokenizedTagItem tag)
 {
     TagApplied?.Invoke(this, new TokenizedTagEventArgs(tag));
 }
Esempio n. 11
0
 /// <summary>
 ///     Raises the TagClick event
 /// </summary>
 internal void RaiseTagClick(TokenizedTagItem tag)
 {
     TagClick?.Invoke(this, new TokenizedTagEventArgs(tag));
 }