Exemplo n.º 1
0
        private void IntitiateDatabind(IEnumerable oldItems, IEnumerable items)
        {
            if (this.tagPanel != null)
            {
                if (oldItems is INotifyCollectionChanged)
                {
                    ((INotifyCollectionChanged)items).CollectionChanged -= ItemsSourceCollectionChanged;
                }

                this.tagPanel.Children.Clear();

                if (items is INotifyCollectionChanged)
                {
                    ((INotifyCollectionChanged)items).CollectionChanged += ItemsSourceCollectionChanged;
                }

                foreach (var current in items)
                {
                    AddTag(NewUnresolved());
                    var resolvedTag = new ResolvedTag
                    {
                        DataContext = current
                    };

                    if (TagStyle != null)
                    {
                        resolvedTag.Style = TagStyle;
                    }

                    AddTag(resolvedTag);
                }

                AddTag(NewUnresolved());
            }
        }
Exemplo n.º 2
0
        private void InsertItem(int index, object item)
        {
            var children = this.tagPanel.Children;

            var resolvedTag = new ResolvedTag {
                DataContext = item
            };

            if (TagStyle != null)
            {
                resolvedTag.Style = TagStyle;
            }

            var resolvedTag2 = resolvedTag;

            resolvedTag2.ShowAddAnimation = true;

            InsertTag(index, resolvedTag2);

            if (index == 0)
            {
                InsertTag(index, NewUnresolved());
            }

            if (children.IndexOf(resolvedTag2) == children.Count - 1)
            {
                InsertTag(children.IndexOf(resolvedTag2) + 1, NewUnresolved());
            }

            if (!(children[children.IndexOf(resolvedTag2) - 1] is UnresolvedTag))
            {
                InsertTag(children.IndexOf(resolvedTag2), NewUnresolved());
            }

            if (!(children[children.IndexOf(resolvedTag2) + 1] is UnresolvedTag))
            {
                InsertTag(children.IndexOf(resolvedTag2) + 1, NewUnresolved());
            }

            var relativeIndex = GetRelativeIndex(resolvedTag2);

            EnableChangePropagation = false;

            if (!Propagating)
            {
                ItemsSource?.Insert(relativeIndex, item);
            }

            EnableChangePropagation = true;

            resolvedTag2.AddCompleted += delegate {
                tagScrollViewer.ScrollIntoView(resolvedTag);
            };
        }