protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec) { base.OnMeasure(widthMeasureSpec, heightMeasureSpec); var availableSize = ViewHelper.LogicalSizeFromSpec(widthMeasureSpec, heightMeasureSpec); if (!double.IsNaN(Width) || !double.IsNaN(Height)) { availableSize = new Windows.Foundation.Size( double.IsNaN(Width) ? availableSize.Width : Width, double.IsNaN(Height) ? availableSize.Height : Height ); } var measuredSize = _layouter.Measure(availableSize); measuredSize = measuredSize.LogicalToPhysicalPixels(); // Report our final dimensions. SetMeasuredDimension( (int)measuredSize.Width, (int)measuredSize.Height ); IFrameworkElementHelper.OnMeasureOverride(this); }
protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec) { base.OnMeasure(widthMeasureSpec, heightMeasureSpec); var availableSize = ViewHelper.LogicalSizeFromSpec(widthMeasureSpec, heightMeasureSpec); var measuredSize = _layouter.Measure(availableSize); if ( !double.IsInfinity(availableSize.Width) && !double.IsInfinity(availableSize.Height) ) { measuredSize = this.AdjustSize(availableSize, measuredSize); } measuredSize = measuredSize.LogicalToPhysicalPixels(); // Report our final dimensions. SetMeasuredDimension( (int)measuredSize.Width, (int)measuredSize.Height ); IFrameworkElementHelper.OnMeasureOverride(this); }
protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec) { var measuredSize = ((ILayouterElement)this).OnMeasureInternal(widthMeasureSpec, heightMeasureSpec); //We call ViewPager.OnMeasure here, because it creates the page views. base.OnMeasure( ViewHelper.SpecFromLogicalSize(measuredSize.Width), ViewHelper.SpecFromLogicalSize(measuredSize.Height) ); IFrameworkElementHelper.OnMeasureOverride(this); }
//TODO generated code - but note call of base.OnMeasure protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec) { var availableSize = ViewHelper.LogicalSizeFromSpec(widthMeasureSpec, heightMeasureSpec); if (!double.IsNaN(Width) || !double.IsNaN(Height)) { availableSize = new Size( double.IsNaN(Width) ? availableSize.Width : Width, double.IsNaN(Height) ? availableSize.Height : Height ); } var measuredSize = _layouter.Measure(availableSize); //We call ViewPager.OnMeasure here, because it creates the page views. base.OnMeasure( ViewHelper.SpecFromLogicalSize(measuredSize.Width), ViewHelper.SpecFromLogicalSize(measuredSize.Height) ); IFrameworkElementHelper.OnMeasureOverride(this); }
protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec) { RectF pathBounds = new RectF(); var path = this.GetPath(); if (path != null) { path.ComputeBounds(pathBounds, false); } _pathWidth = pathBounds.Width(); _pathHeight = pathBounds.Height(); if (ShouldPreserveOrigin) { _pathWidth += pathBounds.Left; _pathHeight += pathBounds.Top; } var aspectRatio = _pathWidth / _pathHeight; var widthMode = ViewHelper.MeasureSpecGetMode(widthMeasureSpec); var heightMode = ViewHelper.MeasureSpecGetMode(heightMeasureSpec); var availableWidth = ViewHelper.MeasureSpecGetSize(widthMeasureSpec); var availableHeight = ViewHelper.MeasureSpecGetSize(heightMeasureSpec); var userWidth = ViewHelper.LogicalToPhysicalPixels(this.Width); var userHeight = ViewHelper.LogicalToPhysicalPixels(this.Height); switch (widthMode) { case Android.Views.MeasureSpecMode.AtMost: case Android.Views.MeasureSpecMode.Exactly: _controlWidth = availableWidth; break; default: case Android.Views.MeasureSpecMode.Unspecified: switch (Stretch) { case Stretch.Uniform: if (heightMode != Android.Views.MeasureSpecMode.Unspecified) { _controlWidth = availableHeight * aspectRatio; } else { _controlWidth = _pathWidth; } break; default: _controlWidth = _pathWidth; break; } break; } switch (heightMode) { case Android.Views.MeasureSpecMode.AtMost: case Android.Views.MeasureSpecMode.Exactly: _controlHeight = availableHeight; break; default: case Android.Views.MeasureSpecMode.Unspecified: switch (Stretch) { case Stretch.Uniform: if (widthMode != Android.Views.MeasureSpecMode.Unspecified) { _controlHeight = availableWidth / aspectRatio; } else { _controlHeight = _pathHeight; } break; default: _controlHeight = _pathHeight; break; } break; } // Default values _calculatedWidth = LimitWithUserSize(_controlWidth, userWidth, _pathWidth); _calculatedHeight = LimitWithUserSize(_controlHeight, userHeight, _pathHeight); _scaleX = (_calculatedWidth - this.PhysicalStrokeThickness) / _pathWidth; _scaleY = (_calculatedHeight - this.PhysicalStrokeThickness) / _pathHeight; // Here we will override some of the default values switch (this.Stretch) { // If the Stretch is None, the drawing is not the same size as the control case Media.Stretch.None: _scaleX = 1; _scaleY = 1; _calculatedWidth = (double)_pathWidth; _calculatedHeight = (double)_pathHeight; break; case Media.Stretch.Fill: break; // Override the _calculated dimensions if the stretch is Uniform or UniformToFill case Media.Stretch.Uniform: var scale = Math.Min(_scaleX, _scaleY); _calculatedWidth = _pathWidth * scale; _calculatedHeight = _pathHeight * scale; break; case Media.Stretch.UniformToFill: scale = Math.Max(_scaleX, _scaleY); _calculatedWidth = _pathWidth * scale; _calculatedHeight = _pathHeight * scale; break; } _calculatedWidth += this.PhysicalStrokeThickness; _calculatedHeight += this.PhysicalStrokeThickness; SetMeasuredDimension((int)Math.Ceiling(_calculatedWidth), (int)Math.Ceiling(_calculatedHeight)); IFrameworkElementHelper.OnMeasureOverride(this); }