Ejemplo n.º 1
0
        public object ItemFromContainer(DependencyObject container)
        {
            object item;

            ContainerItemMap.TryGetValue(container, out item);
            return(item ?? DependencyProperty.UnsetValue);
        }
Ejemplo n.º 2
0
 internal void RemoveAll()
 {
     foreach (var pair in ContainerItemMap)
     {
         Owner.ClearContainerForItem(pair.Key, pair.Value);
     }
     RealizedElements.Clear();
     ContainerIndexMap.Clear();
     ContainerItemMap.Clear();
 }
Ejemplo n.º 3
0
        internal void Remove(GeneratorPosition position, int count)
        {
            CheckOffsetAndRealized(position, count);

            int index = IndexFromGeneratorPosition(position);

            for (int i = 0; i < count; i++)
            {
                var container = ContainerIndexMap [index + i];
                var item      = ContainerItemMap [container];
                ContainerIndexMap.Remove(container, index + i);
                ContainerItemMap.Remove(container);
                RealizedElements.Remove(index + i);
                Owner.ClearContainerForItem(container, item);
            }
        }
Ejemplo n.º 4
0
        internal DependencyObject GenerateNext(out bool isNewlyRealized)
        {
            if (GenerationState == null)
            {
                throw new InvalidOperationException("Cannot call GenerateNext before calling StartAt");
            }

            int index;
            // This is relative to the realised elements.
            int startAt = GenerationState.Position.Index;

            if (startAt == -1)
            {
                if (GenerationState.Position.Offset < 0)
                {
                    index = Owner.Items.Count + GenerationState.Position.Offset;
                }
                else if (GenerationState.Position.Offset == 0)
                {
                    index = 0;
                }
                else
                {
                    index = GenerationState.Position.Offset - 1;
                }
            }
            else if (startAt >= 0 && startAt < RealizedElements.Count)
            {
                // We're starting relative to an already realised element
                index = RealizedElements [startAt] + GenerationState.Position.Offset;
            }
            else
            {
                index = -1;
            }

            bool alreadyRealized = RealizedElements.Contains(index);

            if (!GenerationState.AllowStartAtRealizedItem && alreadyRealized && GenerationState.Position.Offset == 0)
            {
                index          += GenerationState.Step;
                alreadyRealized = RealizedElements.Contains(index);
            }

            if (index < 0 || index >= Owner.Items.Count)
            {
                isNewlyRealized = false;
                return(null);
            }

            if (alreadyRealized)
            {
                GenerationState.Position = new GeneratorPosition(RealizedElements.IndexOf(index), GenerationState.Step);
                isNewlyRealized          = false;

                return(ContainerIndexMap [index]);
            }

            DependencyObject container;
            var item = Owner.Items [index];

            if (Owner.IsItemItsOwnContainer(item))
            {
                container       = (DependencyObject)item;
                isNewlyRealized = true;
            }
            else
            {
                if (Cache.Count == 0)
                {
                    container       = Owner.GetContainerForItem();
                    isNewlyRealized = true;
                }
                else
                {
                    container       = Cache.Dequeue();
                    isNewlyRealized = false;
                }

                ContentControl c = container as ContentControl;
                if (c != null)
                {
                    c.ContentSetsParent = false;
                }
            }

            FrameworkElement f = container as FrameworkElement;

            if (f != null && !(item is UIElement))
            {
                f.DataContext = item;
            }

            RealizedElements.Add(index);
            ContainerIndexMap.Add(container, index);
            ContainerItemMap.Add(container, item);

            GenerationState.Position = new GeneratorPosition(RealizedElements.IndexOf(index), GenerationState.Step);
            return(container);
        }