コード例 #1
0
        public UICollectionViewCell CreateMeasurementCell(NSIndexPath indexPath)
        {
            if (ItemsView.ItemTemplate == null)
            {
                var frame = new CGRect(0, 0, ItemsViewLayout.EstimatedItemSize.Width, ItemsViewLayout.EstimatedItemSize.Height);

                DefaultCell cell;
                if (ItemsViewLayout.ScrollDirection == UICollectionViewScrollDirection.Horizontal)
                {
                    cell = new HorizontalDefaultCell(frame);
                }
                else
                {
                    cell = new VerticalDefaultCell(frame);
                }

                UpdateDefaultCell(cell, indexPath);
                return(cell);
            }

            TemplatedCell templatedCell = CreateAppropriateCellForLayout();

            UpdateTemplatedCell(templatedCell, indexPath);

            // Keep this cell around, we can transfer the contents to the actual cell when the UICollectionView creates it
            _measurementCells[ItemsSource[indexPath]] = templatedCell;

            return(templatedCell);
        }
コード例 #2
0
        protected virtual void UpdateTemplatedCell(TemplatedCell cell, NSIndexPath indexPath)
        {
            cell.ContentSizeChanged      -= CellContentSizeChanged;
            cell.LayoutAttributesChanged -= CellLayoutAttributesChanged;

            var bindingContext = ItemsSource[indexPath];

            // If we've already created a cell for this index path (for measurement), re-use the content
            if (_measurementCells.TryGetValue(bindingContext, out TemplatedCell measurementCell))
            {
                _measurementCells.Remove(bindingContext);
                measurementCell.ContentSizeChanged      -= CellContentSizeChanged;
                measurementCell.LayoutAttributesChanged -= CellLayoutAttributesChanged;
                cell.UseContent(measurementCell);
            }
            else
            {
                cell.Bind(ItemsView.ItemTemplate, ItemsSource[indexPath], ItemsView);
            }

            cell.ContentSizeChanged      += CellContentSizeChanged;
            cell.LayoutAttributesChanged += CellLayoutAttributesChanged;

            ItemsViewLayout.PrepareCellForLayout(cell);
        }
コード例 #3
0
        protected virtual void UpdateTemplatedCell(TemplatedCell cell, NSIndexPath indexPath)
        {
            ApplyTemplateAndDataContext(cell, indexPath);

            if (cell is ItemsViewCell constrainedCell)
            {
                _layout.PrepareCellForLayout(constrainedCell);
            }
        }
コード例 #4
0
        void UpdateTemplatedSupplementaryView(TemplatedCell cell, NSString elementKind, NSIndexPath indexPath)
        {
            ApplyTemplateAndDataContext(cell, elementKind, indexPath);

            if (cell is ItemsViewCell constrainedCell)
            {
                cell.ConstrainTo(ItemsViewLayout.ConstrainedDimension);
            }
        }
コード例 #5
0
 internal void UseContent(TemplatedCell measurementCell)
 {
     // Copy all the content and values from the measurement cell
     ConstrainedDimension = measurementCell.ConstrainedDimension;
     ConstrainedSize      = measurementCell.ConstrainedSize;
     CurrentTemplate      = measurementCell.CurrentTemplate;
     _size = measurementCell._size;
     SetRenderer(measurementCell.VisualElementRenderer);
 }
コード例 #6
0
        protected virtual void UpdateTemplatedCell(TemplatedCell cell, NSIndexPath indexPath)
        {
            cell.ContentSizeChanged -= CellContentSizeChanged;

            cell.Bind(ItemsView, ItemsSource[indexPath]);

            cell.ContentSizeChanged += CellContentSizeChanged;

            ItemsViewLayout.PrepareCellForLayout(cell);
        }
コード例 #7
0
        void ApplyTemplateAndDataContext(TemplatedCell cell, NSIndexPath indexPath)
        {
            // We need to create a renderer, which means we need a template
            var view = _itemsView.ItemTemplate.CreateContent() as View;

            _itemsView.AddLogicalChild(view);
            var renderer = CreateRenderer(view);

            BindableObject.SetInheritedBindingContext(view, _itemsSource[indexPath.Row]);
            cell.SetRenderer(renderer);
        }
コード例 #8
0
        void ApplyTemplateAndDataContext(TemplatedCell cell, NSIndexPath indexPath)
        {
            // We need to create a renderer, which means we need a template
            var templateElement             = _itemsView.ItemTemplate.CreateContent() as View;
            IVisualElementRenderer renderer = CreateRenderer(templateElement);

            if (renderer != null)
            {
                BindableObject.SetInheritedBindingContext(renderer.Element, _itemsSource[indexPath.Row]);
                cell.SetRenderer(renderer);
            }
        }
コード例 #9
0
        void UpdateTemplatedSupplementaryView(TemplatedCell cell, NSString elementKind, NSIndexPath indexPath)
        {
            DataTemplate template = elementKind == UICollectionElementKindSectionKey.Header
                                ? ItemsView.GroupHeaderTemplate
                                : ItemsView.GroupFooterTemplate;

            var bindingContext = ItemsSource.Group(indexPath);

            cell.Bind(template, bindingContext, ItemsView);

            if (cell is ItemsViewCell)
            {
                cell.ConstrainTo(ItemsViewLayout.ConstrainedDimension);
            }
        }
コード例 #10
0
ファイル: ItemsViewController.cs プロジェクト: mmitche/maui
        public TemplatedCell CreateMeasurementCell(NSIndexPath indexPath)
        {
            if (ItemsView.ItemTemplate == null)
            {
                return(null);
            }

            TemplatedCell templatedCell = CreateAppropriateCellForLayout();

            UpdateTemplatedCell(templatedCell, indexPath);

            // Keep this cell around, we can transfer the contents to the actual cell when the UICollectionView creates it
            _measurementCells[indexPath] = templatedCell;

            return(templatedCell);
        }
コード例 #11
0
        void ApplyTemplateAndDataContext(TemplatedCell cell, NSString elementKind, NSIndexPath indexPath)
        {
            DataTemplate template;

            if (elementKind == UICollectionElementKindSectionKey.Header)
            {
                template = GroupableItemsView.GroupHeaderTemplate;
            }
            else
            {
                template = GroupableItemsView.GroupFooterTemplate;
            }

            var templateElement = template.CreateContent() as View;
            var renderer        = CreateRenderer(templateElement);

            BindableObject.SetInheritedBindingContext(renderer.Element, ItemsSource.Group(indexPath));
            cell.SetRenderer(renderer);
        }
コード例 #12
0
        void ApplyTemplateAndDataContext(TemplatedCell cell, NSIndexPath indexPath)
        {
            var template = _itemsView.ItemTemplate;
            var item     = _itemsSource[indexPath.Row];

            // Run this through the extension method in case it's really a DataTemplateSelector
            template = template.SelectDataTemplate(item, _itemsView);

            // Create the content and renderer for the view and
            var view     = template.CreateContent() as View;
            var renderer = CreateRenderer(view);

            cell.SetRenderer(renderer);

            // Bind the view to the data item
            view.BindingContext = _itemsSource[indexPath.Row];

            // And make sure it's a "child" of the ItemsView
            _itemsView.AddLogicalChild(view);
        }
コード例 #13
0
        // These measurement methods are only necessary for iOS 10 and lower
        CGSize MeasureTemplatedSupplementaryCell(NSString elementKind, nint section, NSString reuseId)
        {
            if (_measurementCellTemplated == null)
            {
                if (reuseId == HorizontalSupplementaryView.ReuseId)
                {
                    _measurementCellTemplated = new HorizontalSupplementaryView(CGRect.Empty);
                }
                else if (reuseId == VerticalSupplementaryView.ReuseId)
                {
                    _measurementCellTemplated = new VerticalSupplementaryView(CGRect.Empty);
                }
            }

            if (_measurementCellTemplated == null)
            {
                return(CGSize.Empty);
            }

            UpdateTemplatedSupplementaryView(_measurementCellTemplated, elementKind, NSIndexPath.FromItemSection(0, section));
            return(_measurementCellTemplated.Measure());
        }