internal void EnsureRenderedGeometry() { if (_renderedGeometry == null) { _renderedGeometry = DefiningGeometry; Debug.Assert(_renderedGeometry != null); if (Stretch != Stretch.None) { Geometry currentValue = _renderedGeometry.CloneCurrentValue(); if (Object.ReferenceEquals(_renderedGeometry, currentValue)) { _renderedGeometry = currentValue.Clone(); } else { _renderedGeometry = currentValue; } Transform renderedTransform = _renderedGeometry.Transform; BoxedMatrix boxedStretchMatrix = StretchMatrixField.GetValue(this); Matrix stretchMatrix = (boxedStretchMatrix == null) ? Matrix.Identity : boxedStretchMatrix.Value; if (renderedTransform == null || renderedTransform.IsIdentity) { _renderedGeometry.Transform = new MatrixTransform(stretchMatrix); } else { _renderedGeometry.Transform = new MatrixTransform(renderedTransform.Value * stretchMatrix); } } } }
/// <summary> /// Compute the rendered geometry and the stretching transform. /// </summary> protected override Size ArrangeOverride(Size finalSize) { Size newSize; Stretch mode = Stretch; if (mode == Stretch.None) { StretchMatrixField.ClearValue(this); ResetRenderedGeometry(); newSize = finalSize; } else { newSize = GetStretchedRenderSizeAndSetStretchMatrix( mode, GetStrokeThickness(), finalSize, GetDefiningGeometryBounds()); } if (SizeIsInvalidOrEmpty(newSize)) { // We've encountered a numerical error. Don't draw anything. newSize = new Size(0, 0); _renderedGeometry = Geometry.Empty; } return(newSize); }
internal Size GetStretchedRenderSizeAndSetStretchMatrix(Stretch mode, double strokeThickness, Size availableSize, Rect geometryBounds) { double xScale, yScale, dX, dY; Size renderSize; GetStretchMetrics(mode, strokeThickness, availableSize, geometryBounds, out xScale, out yScale, out dX, out dY, out renderSize); // Construct the matrix Matrix stretchMatrix = Matrix.Identity; stretchMatrix.ScaleAt(xScale, yScale, geometryBounds.Location.X, geometryBounds.Location.Y); stretchMatrix.Translate(dX, dY); StretchMatrixField.SetValue(this, new BoxedMatrix(stretchMatrix)); ResetRenderedGeometry(); return(renderSize); }