public void ItemRemoved(int removed)
        {
            if (_realizedItem.ContainsKey(removed))
            {
                CollectionView.UnrealizeView(_realizedItem[removed].View);
                _realizedItem.Remove(removed);
            }

            var items = _realizedItem.Keys.OrderBy(key => key);

            foreach (var index in items)
            {
                if (index > removed)
                {
                    _realizedItem[index - 1] = _realizedItem[index];
                }
            }

            var last = items.LastOrDefault();

            if (last > removed)
            {
                _realizedItem.Remove(last);
            }

            UpdateRemovedSize(removed);

            _scrollCanvasSize = new Size(0, 0);
        }
 public void Reset()
 {
     foreach (var realizedItem in _realizedItem.Values.ToList())
     {
         CollectionView.UnrealizeView(realizedItem.View);
     }
     _realizedItem.Clear();
     _scrollCanvasSize = new Size(0, 0);
 }
 public void ItemUpdated(int index)
 {
     if (_realizedItem.ContainsKey(index))
     {
         var bound = _realizedItem[index].View.Geometry;
         CollectionView.UnrealizeView(_realizedItem[index].View);
         var view = CollectionView.RealizeView(index);
         _realizedItem[index].View = view;
         view.Geometry             = bound;
     }
 }
Esempio n. 4
0
        public void LayoutItems(Rect bound, bool force)
        {
            if (_allocatedSize.Width <= 0 || _allocatedSize.Height <= 0)
            {
                return;
            }

            // TODO : need to optimization. it was frequently called with similar bound value.
            if (!ShouldRearrange(bound) && !force)
            {
                return;
            }

            _isLayouting = true;
            _last        = bound;

            int padding    = Span;
            int startIndex = Math.Max(GetStartIndex(bound) - padding, 0);
            int endIndex   = Math.Min(GetEndIndex(bound) + padding, CollectionView.Count - 1);

            foreach (var index in _realizedItem.Keys.ToList())
            {
                if (index < startIndex || index > endIndex)
                {
                    CollectionView.UnrealizeView(_realizedItem[index].View);
                    _realizedItem.Remove(index);
                }
            }

            var parent = CollectionView.ParentPosition;

            for (int i = startIndex; i <= endIndex; i++)
            {
                EvasObject itemView;
                if (!_realizedItem.ContainsKey(i))
                {
                    var view = CollectionView.RealizeView(i);

                    _realizedItem[i] = new RealizedItem(view, i);
                    itemView         = view;
                }
                else
                {
                    itemView = _realizedItem[i].View;
                }

                var itemBound = GetItemBound(i);
                itemBound.X      += parent.X;
                itemBound.Y      += parent.Y;
                itemView.Geometry = itemBound;
            }
            _isLayouting = false;
        }