Export (0) Print
Expand All

Stroke.OnInvalidated Method

Raises the Invalidated event.

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

protected virtual void OnInvalidated(
	EventArgs e


Type: System.EventArgs

An EventArgs that contains the event data.

If you inherit from the Stroke class and your stroke's appearance is based on a custom state, you must call the OnInvalidated method to raise the Invalidated event. The InkPresenter handles the Invalidated event and calls the DrawCore method.

The following example draws a Stroke either as a solid stroke or as a series of StylusPoint objects, depending on the Mode property. The example calls the OnInvalidated method, which in turn calls the DrawCore where the stroke is drawn.

// Enumerator that specifies the drawing mode of the stroke. 
public enum DrawingMode


private DrawingMode strokeMode = DrawingMode.Solid;

// Property that specifies whether to draw a solid stroke or the stylus points 
public DrawingMode Mode
        return strokeMode;

        if (strokeMode != value)
            strokeMode = value;
            this.OnInvalidated(new EventArgs());

protected override void DrawCore(System.Windows.Media.DrawingContext context, DrawingAttributes overrides)
    SolidColorBrush strokeBrush = new SolidColorBrush(overrides.Color);

    // If strokeMode it set to Solid, draw the strokes regularly. 
    // Otherwise, draw the stylus points. 
    if (strokeMode == DrawingMode.Solid)
        Geometry geometry = GetGeometry(overrides);
        context.DrawGeometry(strokeBrush, null, geometry);
    else // strokeMode == DrawingMode.StylusPoints
        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(strokeBrush, 1), (Point)p, 5, 5);

.NET Framework

Supported in: 4.6, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft