コード例 #1
0
        private void AddSection(NotifyCollectionChangedEventArgs e)
        {
            // regard as coming only one item.
            if (e.NewItems[0] is not Section section)
            {
                return;
            }
            int startIndex = RowIndexFromParentCollection(e.NewStartingIndex);

            Insert(startIndex, new RowInfo(section, ViewType.CustomHeader));
            // Insert(startIndex, new RowInfo(section, section.HeaderView == null ? ViewType.TextHeader : ViewType.CustomHeader));

            for (var i = 0; i < section.Count; i++)
            {
                Cell cell = section[i];
                if (!ViewTypes.ContainsKey(cell.GetType()))
                {
                    ViewTypes.Add(cell.GetType(), GetNextTypeIndex());
                }

                var rowInfo = new RowInfo(section, cell, (ViewType)ViewTypes[cell.GetType()]);

                Insert(i + 1 + startIndex, rowInfo);
            }

            Insert(startIndex + section.Count() + 1, new RowInfo(section, ViewType.CustomFooter));
            // Insert(startIndex + section.Count() + 1, new RowInfo(section, section.FooterView == null ? ViewType.TextFooter : ViewType.CustomFooter));

            _Adapter.NotifyItemRangeInserted(startIndex, section.Count + 2);             // add a header and footer
        }
コード例 #2
0
        private void AddCell(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (!(sender is Section section))
            {
                throw new ArgumentException("Sender must be of type(Section)", nameof(sender));
            }

            int         startIndex = RowIndexFromChildCollection(section, e.NewStartingIndex);
            List <Cell> newCells   = e.NewItems.Cast <Cell>().ToList();

            for (var i = 0; i < newCells.Count; i++)
            {
                Cell cell = newCells[i];
                if (!ViewTypes.ContainsKey(cell.GetType()))
                {
                    ViewTypes.Add(cell.GetType(), GetNextTypeIndex());
                }

                var rowInfo = new RowInfo(section, cell, (ViewType)ViewTypes[cell.GetType()]);
                Insert(i + startIndex, rowInfo);
            }

            _Adapter.NotifyItemRangeInserted(startIndex, newCells.Count);
        }