internal static Size GetDesiredSizeFromHandler(this IViewHandler viewHandler, double widthConstraint, double heightConstraint) { var Context = viewHandler.MauiContext?.Context; var platformView = viewHandler.ToPlatform(); var virtualView = viewHandler.VirtualView; if (platformView == null || virtualView == null || Context == null) { return(Size.Zero); } // Create a spec to handle the native measure var widthSpec = Context.CreateMeasureSpec(widthConstraint, virtualView.Width, virtualView.MaximumWidth); var heightSpec = Context.CreateMeasureSpec(heightConstraint, virtualView.Height, virtualView.MaximumHeight); var packed = PlatformInterop.MeasureAndGetWidthAndHeight(platformView, widthSpec, heightSpec); var measuredWidth = (int)(packed >> 32); var measuredHeight = (int)(packed & 0xffffffffL); // Convert back to xplat sizes for the return value return(Context.FromPixels(measuredWidth, measuredHeight)); }