Exemple #1
0
        public override void LayoutSubviews()
        {
            base.LayoutSubviews();

            if (_previousFrame != Frame)
            {
                UpdateCellSize();
                UpdateGroupHeaderWidth();
                ViewLayout.InvalidateLayout();
            }
            _previousFrame = Frame;
        }
 protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     base.OnElementPropertyChanged(sender, e);
     if (e.PropertyName == GridCollectionView.GroupHeaderHeightProperty.PropertyName)
     {
         UpdateGroupHeaderHeight();
         ViewLayout.InvalidateLayout();
     }
     else if (e.PropertyName == GridCollectionView.GridTypeProperty.PropertyName ||
              e.PropertyName == GridCollectionView.PortraitColumnsProperty.PropertyName ||
              e.PropertyName == GridCollectionView.LandscapeColumnsProperty.PropertyName ||
              e.PropertyName == GridCollectionView.ColumnSpacingProperty.PropertyName ||
              e.PropertyName == GridCollectionView.ColumnHeightProperty.PropertyName ||
              e.PropertyName == GridCollectionView.SpacingTypeProperty.PropertyName ||
              e.PropertyName == GridCollectionView.AdditionalHeightProperty.PropertyName ||
              e.PropertyName == CollectionView.GroupFirstSpacingProperty.PropertyName ||
              e.PropertyName == CollectionView.GroupLastSpacingProperty.PropertyName ||
              e.PropertyName == GridCollectionView.BothSidesMarginProperty.PropertyName)
     {
         UpdateGridType();
         InvalidateLayout();
     }
     else if (e.PropertyName == GridCollectionView.RowSpacingProperty.PropertyName)
     {
         UpdateRowSpacing();
         ViewLayout.InvalidateLayout();
     }
     else if (e.PropertyName == GridCollectionView.ColumnWidthProperty.PropertyName)
     {
         if (_gridCollectionView.GridType != GridType.UniformGrid)
         {
             UpdateGridType();
             InvalidateLayout();
         }
     }
     else if (e.PropertyName == ListView.IsPullToRefreshEnabledProperty.PropertyName)
     {
         UpdatePullToRefreshEnabled();
     }
     else if (e.PropertyName == GridCollectionView.PullToRefreshColorProperty.PropertyName)
     {
         UpdatePullToRefreshColor();
     }
     else if (e.PropertyName == Xamarin.Forms.ListView.IsRefreshingProperty.PropertyName)
     {
         UpdateIsRefreshing();
     }
     else if (e.PropertyName == GridCollectionView.IsGroupHeaderStickyProperty.PropertyName)
     {
         UpdateIsSticky();
         InvalidateLayout();
     }
 }
        void InvalidateLayout()
        {
            if (!_gridCollectionView.IsGroupingEnabled)
            {
                ViewLayout.InvalidateLayout();
                return;
            }

            // HACK: When IsGroupingEnabled is true and changing such layout size as the item size and the spacing size,
            //       a header cell content is sometimes not reflected or broken layout.
            //       By reloading with a bit delay after scrolling to Top, this issue can be avoided.
            Control.SetContentOffset(CGPoint.Empty, false);
            DispatchQueue.MainQueue.DispatchAfter(new DispatchTime(DispatchTime.Now, TimeSpan.FromMilliseconds(150)), () =>
            {
                Control.ReloadData();
                ViewLayout.InvalidateLayout();
            });
        }