protected virtual SizeF NativeMeasureOverride(SizeF availableSize)
        {
            var absoluteAvailableSize = new SizeF(
                ScreenProperties.ConvertDPIToPixels(availableSize.Width),
                ScreenProperties.ConvertDPIToPixels(availableSize.Height));
            var margin = this.Margin;

            var absoluteMargin = new Thickness(
                (int)ScreenProperties.ConvertDPIToPixels(margin.LeftF()),
                (int)ScreenProperties.ConvertDPIToPixels(margin.TopF()),
                (int)ScreenProperties.ConvertDPIToPixels(margin.RightF()),
                (int)ScreenProperties.ConvertDPIToPixels(margin.BottomF()));

            int availableWidth;
            int availableHeight;

            // TODO: Unclear behavior. Incorrect on API 18
            if (double.IsPositiveInfinity(absoluteAvailableSize.Width))
            {
                availableWidth = int.MaxValue;
            }
            else
            {
                availableWidth = (int)(absoluteAvailableSize.Width - absoluteMargin.HorizontalThicknessF());
            }
            if (availableWidth < 0)
            {
                availableWidth = 0;
            }

            if (double.IsPositiveInfinity(absoluteAvailableSize.Height))
            {
                availableHeight = int.MaxValue;
            }
            else
            {
                availableHeight = (int)(absoluteAvailableSize.Height - absoluteMargin.VerticalThicknessF());
            }
            if (availableHeight < 0)
            {
                availableHeight = 0;
            }

            int measuredWidth;
            int measuredHeight;

            switch (this.NativeUIElement.LayoutParameters.Width)
            {
            case ViewGroup.LayoutParams.WrapContent:
                measuredWidth = View.MeasureSpec.MakeMeasureSpec(availableWidth, MeasureSpecMode.AtMost);
                break;

            case ViewGroup.LayoutParams.MatchParent:
                measuredWidth = View.MeasureSpec.MakeMeasureSpec(availableWidth, MeasureSpecMode.Exactly);
                break;

            default:
                measuredWidth = View.MeasureSpec.MakeMeasureSpec(availableWidth, MeasureSpecMode.Exactly);
                break;
            }
            switch (this.NativeUIElement.LayoutParameters.Height)
            {
            case ViewGroup.LayoutParams.WrapContent:
                measuredHeight = View.MeasureSpec.MakeMeasureSpec(availableHeight, MeasureSpecMode.AtMost);
                break;

            case ViewGroup.LayoutParams.MatchParent:
                measuredHeight = View.MeasureSpec.MakeMeasureSpec(availableHeight, MeasureSpecMode.Exactly);
                break;

            default:
                measuredHeight = View.MeasureSpec.MakeMeasureSpec(availableHeight, MeasureSpecMode.Exactly);
                break;
            }

            this.NativeUIElement.Measure(measuredWidth, measuredHeight);

            var absoluteMeasuredSize = new SizeF(
                this.NativeUIElement.MeasuredWidth + absoluteMargin.HorizontalThicknessF(),
                this.NativeUIElement.MeasuredHeight + absoluteMargin.VerticalThicknessF());

            var dpiMeasuredSize = new SizeF(
                Math.Min(ScreenProperties.ConvertPixelsToDPI(absoluteMeasuredSize.Width), availableSize.Width),
                Math.Min(ScreenProperties.ConvertPixelsToDPI(absoluteMeasuredSize.Height), availableSize.Height));

            return(dpiMeasuredSize);
        }