Exemple #1
0
        private void TokenizingTextBoxItem_Click(object sender, RoutedEventArgs e)
        {
            if (sender is TokenizingTextBoxItem item)
            {
                bool isControlDown = CoreWindow.GetForCurrentThread().GetKeyState(VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down);
                if (!item.IsSelected && !isControlDown)
                {
                    foreach (var child in _wrapPanel.Children)
                    {
                        if (child is TokenizingTextBoxItem childItem)
                        {
                            childItem.IsSelected = false;
                        }
                    }

                    SelectedItemsInternal.Clear();
                }

                item.IsSelected = !item.IsSelected;

                if (item.IsSelected)
                {
                    SelectedItemsInternal.Add(item);
                }
                else
                {
                    SelectedItemsInternal.Remove(item);
                }

                TokenItemClicked?.Invoke(this, item); // TODO: Do we want to use EventArgs here to have the OriginalSource like ItemClickEventArgs?
            }
        }
Exemple #2
0
        private void RemoveToken(TokenizingTextBoxItem item)
        {
            var tirea = new TokenItemRemovedEventArgs(item?.Content, item);

            TokenItemRemoved?.Invoke(this, tirea);

            if (tirea.Cancel)
            {
                return;
            }

            SelectedItemsInternal.Remove(item);
            TokenizedItemsInternal.Remove(item);

            var itemIndex = Math.Max(_wrapPanel.Children.IndexOf(item) - 1, 0);

            _wrapPanel.Children.Remove(item);

            if (_wrapPanel.Children[itemIndex] is Control control)
            {
                control.Focus(FocusState.Programmatic);
            }
        }