diff --git a/MPowerKit.VirtualizeListView/Layouts/VirtualizeItemsLayoutManger.cs b/MPowerKit.VirtualizeListView/Layouts/VirtualizeItemsLayoutManger.cs index ed0b50c..32c5636 100644 --- a/MPowerKit.VirtualizeListView/Layouts/VirtualizeItemsLayoutManger.cs +++ b/MPowerKit.VirtualizeListView/Layouts/VirtualizeItemsLayoutManger.cs @@ -682,7 +682,14 @@ protected virtual bool TriggerResizeLayout() PrevContentSize = desiredSize; - (this as IView).InvalidateMeasure(); + View? view = +#if MACIOS + ListView; +#else + this; +#endif + + (view as IView)?.InvalidateMeasure(); return true; } @@ -708,8 +715,7 @@ protected virtual VirtualizeListViewItem CreateDummyItem(DataTemplate template, protected virtual bool IsOrientation(ScrollOrientation orientation) { - return ListView!.Orientation == orientation - || (ListView.Orientation == ScrollOrientation.Neither && ListView.PrevScrollOrientation == orientation); + return ListView!.IsOrientation(orientation); } protected virtual Size GetDesiredLayoutSize(double widthConstraint, double heightConstraint, Size availableSpace) @@ -763,7 +769,8 @@ public virtual Size Measure(double widthConstraint, double heightConstraint) MeasureItem(LaidOutItems, view.Item!, availableSpace); } - return GetDesiredLayoutSize(widthConstraint, heightConstraint, availableSpace); + var desiredSize = GetDesiredLayoutSize(widthConstraint, heightConstraint, availableSpace); + return desiredSize; } public virtual Size ArrangeChildren(Rect bounds) diff --git a/MPowerKit.VirtualizeListView/VirtualizeListView.cs b/MPowerKit.VirtualizeListView/VirtualizeListView.cs index 8af0c55..a352ccc 100644 --- a/MPowerKit.VirtualizeListView/VirtualizeListView.cs +++ b/MPowerKit.VirtualizeListView/VirtualizeListView.cs @@ -314,6 +314,38 @@ public virtual void AdjustScroll(double dx, double dy) #endif } + public virtual bool IsOrientation(ScrollOrientation orientation) + { + return Orientation == orientation + || (Orientation == ScrollOrientation.Neither && PrevScrollOrientation == orientation); + } + + protected override Size MeasureOverride(double widthConstraint, double heightConstraint) + { + var size = base.MeasureOverride(widthConstraint, heightConstraint); + + var orientation = ScrollOrientation.Neither; + if (IsOrientation(ScrollOrientation.Both)) orientation = ScrollOrientation.Both; + else if (IsOrientation(ScrollOrientation.Vertical)) orientation = ScrollOrientation.Vertical; + else if (IsOrientation(ScrollOrientation.Horizontal)) orientation = ScrollOrientation.Horizontal; + + var desiredWidth = size.Width; + if (orientation is ScrollOrientation.Both or ScrollOrientation.Horizontal && HorizontalOptions != LayoutOptions.Fill) + { + desiredWidth = Padding.HorizontalThickness + Margin.HorizontalThickness + + (Content?.DesiredSize.Width ?? 0d); + } + + var desiredHeight = size.Height; + if (orientation is ScrollOrientation.Both or ScrollOrientation.Vertical && VerticalOptions != LayoutOptions.Fill) + { + desiredHeight = Padding.VerticalThickness + Margin.VerticalThickness + + (Content?.DesiredSize.Height ?? 0d); + } + + return new Size(Math.Min(desiredWidth, widthConstraint), Math.Min(desiredHeight, heightConstraint)); + } + #region Adapter public DataAdapter Adapter {