internal static Size ApplySizeConstraints(this IFrameworkElement e, Size forSize) { var(min, max) = e.GetMinMax(); return(forSize .AtMost(max) .AtLeast(min)); // UWP is applying "min" after "max", so if "min" > "max", "min" wins }
public static CGSize SizeThatFits(IFrameworkElement e, CGSize size) { // Note that on iOS, the computation is intentionally kept as nfloat // to handle discrepancies with the nfloat.NaN and double.NaN. if (e.Visibility == Visibility.Collapsed) { return(new CGSize(0, 0)); } var(min, max) = e.GetMinMax(); var width = size .Width .NumberOrDefault(nfloat.PositiveInfinity) .LocalMin((nfloat)max.Width) .LocalMax((nfloat)min.Width); var height = size .Height .NumberOrDefault(nfloat.PositiveInfinity) .LocalMin((nfloat)max.Height) .LocalMax((nfloat)min.Height); return(new CGSize(width, height)); }