private void DrawGuideLine(DrawingContext dc, BasicStyleCache cache, GuidePoint point0, GuidePoint point1) { var gs = new GuidelineSet( new double[] { point0.X + cache.HalfThickness, point1.X + cache.HalfThickness }, new double[] { point0.Y + cache.HalfThickness, point1.Y + cache.HalfThickness }); gs.Freeze(); dc.PushGuidelineSet(gs); dc.DrawLine(cache.StrokePen, new Point(point0.X, point0.Y), new Point(point1.X, point1.Y)); dc.Pop(); }
private void DrawImage(DrawingContext dc, Rect rect) { ImageSource source = Image; if (source != null) { double opacity = ImageOpacity; if (IsNineGrid) { // make sure we don't step out of borders Thickness margin = Clamp(ImageMargin, new Size(source.Width, source.Height), rect.Size); double[] xGuidelines = { 0, margin.Left, rect.Width - margin.Right, rect.Width }; double[] yGuidelines = { 0, margin.Top, rect.Height - margin.Bottom, rect.Height }; GuidelineSet guidelineSet = new GuidelineSet(xGuidelines, yGuidelines); guidelineSet.Freeze(); dc.PushGuidelineSet(guidelineSet); double[] vx = { 0D, margin.Left / source.Width, (source.Width - margin.Right) / source.Width, 1D }; double[] vy = { 0D, margin.Top / source.Height, (source.Height - margin.Bottom) / source.Height, 1D }; double[] x = { rect.Left, rect.Left + margin.Left, rect.Right - margin.Right, rect.Right }; double[] y = { rect.Top, rect.Top + margin.Top, rect.Bottom - margin.Bottom, rect.Bottom }; for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { var brush = new ImageBrush(source) { Opacity = opacity, Viewbox = new Rect(vx[j], vy[i], Math.Max(0D, (vx[j + 1] - vx[j])), Math.Max(0D, (vy[i + 1] - vy[i]))) }; dc.DrawRectangle(brush, null, new Rect(x[j], y[i], Math.Max(0D, (x[j + 1] - x[j])), Math.Max(0D, (y[i + 1] - y[i])))); } } dc.Pop(); } else { var brush = new ImageBrush(source) { Opacity = opacity }; dc.DrawRectangle(brush, null, rect); } } }
/// <summary> /// PushGuidelineY2 - /// Explicitly push a pair of horizontal guidelines. /// </summary> /// <param name="leadingCoordinate"> The coordinate of leading guideline. </param> /// <param name="offsetToDrivenCoordinate"> /// The offset from leading guideline to driven guideline. /// </param> internal override void PushGuidelineY2( Double leadingCoordinate, Double offsetToDrivenCoordinate) { #if DEBUG MediaTrace.DrawingContextOp.Trace("PushGuidelineY2"); #endif // // Verify that parameters & state are valid // VerifyApiNonstructuralChange(); // // Instantiate a new drawing group and set it as the _currentDrawingGroup // PushNewDrawingGroup(); // // Convert compact record to generic GuidelineSet. // GuidelineSet guidelineCollection = new GuidelineSet( null, // x guidelines new double[] { leadingCoordinate, offsetToDrivenCoordinate }, // y guidelines true // dynamic flag ); guidelineCollection.Freeze(); // // Set the guideline collection on the new DrawingGroup // _currentDrawingGroup.GuidelineSet = guidelineCollection; }