Stroke.DrawCore Method (DrawingContext, DrawingAttributes)


Renders the Stroke on the specified DrawingContext using the specified DrawingAttributes.

Namespace:   System.Windows.Ink
Assembly:  PresentationCore (in PresentationCore.dll)

protected virtual void DrawCore(
	DrawingContext drawingContext,
	DrawingAttributes drawingAttributes


Type: System.Windows.Media.DrawingContext

The DrawingContext object onto which the stroke will be rendered.

Type: System.Windows.Ink.DrawingAttributes

The DrawingAttributes object defining the attributes of the stroke that is drawn.

Override the DrawCore method to perform custom drawing when you inherit from the Stroke class.

The following example demonstrates how to draw a circle at each StylusPoint of a Stroke. If the FitToCurve property is set to true, the GetBezierStylusPoints is used to get the stylus points. Otherwise, the StylusPoints property is used.

protected override void DrawCore(DrawingContext context, DrawingAttributes overrides)
    // Draw the stroke. Calling base.DrawCore accomplishes the same thing.
    Geometry geometry = GetGeometry(overrides);
    context.DrawGeometry(new SolidColorBrush(overrides.Color), null, geometry);

    StylusPointCollection points;

    // Get the stylus points used to draw the stroke.  The points used depends on
    // the value of FitToCurve.
    if (this.DrawingAttributes.FitToCurve)
        points = this.GetBezierStylusPoints();
        points = this.StylusPoints;

    // Draw a circle at each stylus point.
    foreach (StylusPoint p in points)
        context.DrawEllipse(null, new Pen(Brushes.Black, 1), (Point)p, 5, 5);


.NET Framework
Available since 3.0
Return to top