void CleanUpAdapter()
 {
     if (_adapter != null)
     {
         _adapter.Dispose();
         _adapter = null;
     }
 }
        protected override void OnElementChanged(ElementChangedEventArgs <XamGridView> e)
        {
            base.OnElementChanged(e);

            try
            {
                var context        = Xamarin.Forms.Forms.Context;
                var collectionView = new AGridView(context);
                collectionView.SetGravity(GravityFlags.Center);
                collectionView.StretchMode = StretchMode.StretchColumnWidth;

                var metrics     = Resources.DisplayMetrics;
                var width       = metrics.WidthPixels;
                var spacing     = (int)e.NewElement.ColumnSpacing * 3;
                int noOfColumns = (int)e.NewElement.NoOfColumns;
                int itemWidth   = width / noOfColumns - spacing;

                collectionView.SetNumColumns(noOfColumns);
                collectionView.SetBackgroundColor(Element.BackgroundColor.ToAndroid());
                collectionView.SetHorizontalSpacing(spacing);
                collectionView.SetVerticalSpacing(spacing);

                this.Unbind(e.OldElement);
                this.Bind(e.NewElement);

                _adapter = new GridViewAdapter(context, collectionView, Element, itemWidth);
                collectionView.Adapter    = _adapter;
                collectionView.ItemClick += CollectionViewItemClick;

                base.SetNativeControl(collectionView);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex?.Message);
            }
        }