protected Size MeasureChildOverride(View view, Size slotSize) { var ret = view .SizeThatFits(slotSize.LogicalToPhysicalPixels()) .PhysicalToLogicalPixels() .ToFoundationSize(); // With iOS, a child may return a size that fits that is larger than the suggested size. // We don't want that with respects to the Xaml model, so we cap the size to the input constraints. if (nfloat.IsNaN((nfloat)ret.Width) || nfloat.IsNaN((nfloat)ret.Height)) { ret.ToString(); } if (!(view is FrameworkElement) && view is IFrameworkElement ife) { if (!(view is Image)) // Except for Image { // If the child is not a FrameworkElement, part of the "Measure" // phase must be done by the parent element's layouter. // Here, it means adding the margin to the measured size. ret = ret.Add(ife.Margin); } } var w = nfloat.IsNaN((nfloat)ret.Width) ? double.PositiveInfinity : Math.Min(slotSize.Width, ret.Width); var h = nfloat.IsNaN((nfloat)ret.Height) ? double.PositiveInfinity : Math.Min(slotSize.Height, ret.Height); return(new Size(w, h)); }
protected Size MeasureChildOverride(View view, Size slotSize) { var ret = view .SizeThatFits(slotSize.LogicalToPhysicalPixels()) .PhysicalToLogicalPixels() .ToFoundationSize(); // With iOS, a child may return a size that fits that is larger than the suggested size. // We don't want that with respects to the Xaml model, so we cap the size to the input constraints. if (nfloat.IsNaN((nfloat)ret.Width) || nfloat.IsNaN((nfloat)ret.Height)) { ret.ToString(); } ret.Width = nfloat.IsNaN((nfloat)ret.Width) ? double.PositiveInfinity : Math.Min(slotSize.Width, ret.Width); ret.Height = nfloat.IsNaN((nfloat)ret.Height) ? double.PositiveInfinity : Math.Min(slotSize.Height, ret.Height); return(ret); }