Exemplo n.º 1
0
        public void RecycleCell(object data, DataTemplate dataTemplate, VisualElement parent)
        {
            if (_viewCell == null)
            {
                _viewCell = (dataTemplate.CreateContent() as FastGridCell);

                //reflection method of setting isplatformenabled property
                // We are going to re - set the Platform here because in some cases (headers mostly) its possible this is unset and
                //   when the binding context gets updated the measure passes will all fail.By applying this here the Update call
                // further down will result in correct layouts.
                //var p = PlatformProperty.GetValue(parent);
                //PlatformProperty.SetValue(_viewCell, p);

                _viewCell.BindingContext = data;
                _viewCell.Parent         = parent;
                _viewCell.PrepareCell(new Size(Bounds.Width, Bounds.Height));
                _originalBindingContext = _viewCell.BindingContext;
                var renderer = Platform.CreateRenderer(_viewCell.View); //RendererFactory.GetRenderer (_viewCell.View);
                _view = renderer.NativeView;

                _view.AutoresizingMask = UIViewAutoresizing.All;
                _view.ContentMode      = UIViewContentMode.ScaleToFill;

                ContentView.AddSubview(_view);
                return;
            }
            else if (data == _originalBindingContext)
            {
                _viewCell.BindingContext = _originalBindingContext;
            }
            else
            {
                _viewCell.BindingContext = data;
            }
        }
        public void RecycleCell(object data, FastGridTemplateSelector dataTemplate, VisualElement parent)
        {
            if (ViewCell == null)
            {
                var cellSize = new Size(Bounds.Width, Bounds.Height);

                if (!(dataTemplate is FastGridTemplateSelector templateSelector))
                {
                    throw new NotSupportedException(@"DataTemplate should be FastGridTemplateSelector");
                }

                var template = templateSelector.SelectTemplate(data) as FastGridDataTemplate;
                ViewCell = template?.CreateContent() as FastGridCell;
                cellSize = template?.CellSize ?? cellSize;

                if (ViewCell != null)
                {
                    ViewCell.BindingContext = data;
                    ViewCell.PrepareCell(cellSize);
                    ViewCell.Parent = parent;

                    _originalBindingContext = data;
                    _view = ConvertFormsToNative(ViewCell.View, new Rectangle(new Point(0, 0), cellSize));
                }

                if (_view == null)
                {
                    return;
                }

                _view.AutoresizingMask = UIViewAutoresizing.All;
                _view.ContentMode      = UIViewContentMode.ScaleAspectFit;
                _view.ClipsToBounds    = true;

                ContentView.AddSubview(_view);
            }
            else if (data == _originalBindingContext)
            {
                ViewCell.BindingContext = _originalBindingContext;
            }
            else
            {
                ViewCell.BindingContext = data;
            }

            var gr = GestureRecognizers;

            if (gr != null && gr.Length > 0)
            {
                gr.ForEach(RemoveGestureRecognizer);
            }

            _tapGestureRecognizer = new UITapGestureRecognizer(Tapped);
            AddGestureRecognizer(_tapGestureRecognizer);
        }