public virtual SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint) { if (TypedNativeView == null) { return(new SizeRequest(Size.Zero)); } var deviceWidthConstraint = Context.ToPixels(widthConstraint); var deviceHeightConstraint = Context.ToPixels(heightConstraint); var widthSpec = MeasureSpecMode.AtMost.MakeMeasureSpec((int)deviceWidthConstraint); var heightSpec = MeasureSpecMode.AtMost.MakeMeasureSpec((int)deviceHeightConstraint); TypedNativeView.Measure(widthSpec, heightSpec); var deviceIndependentSize = Context.FromPixels(TypedNativeView.MeasuredWidth, TypedNativeView.MeasuredHeight); return(new SizeRequest(deviceIndependentSize)); }
public virtual Size GetDesiredSize(double widthConstraint, double heightConstraint) { if (TypedNativeView == null) { return(Size.Zero); } if (Context == null) { return(new Size(widthConstraint, heightConstraint)); } var deviceWidthConstraint = Context.ToPixels(widthConstraint); var deviceHeightConstraint = Context.ToPixels(heightConstraint); var widthSpec = MeasureSpecMode.Exactly.MakeMeasureSpec((int)deviceWidthConstraint); var heightSpec = MeasureSpecMode.Exactly.MakeMeasureSpec((int)deviceHeightConstraint); TypedNativeView.Measure(widthSpec, heightSpec); return(Context.FromPixels(TypedNativeView.MeasuredWidth, TypedNativeView.MeasuredHeight)); }