This topic has not yet been rated - Rate this topic

Stroke.OnInvalidated Method

Raises the Invalidated event.

Namespace:  System.Windows.Ink
Assembly:  PresentationCore (in PresentationCore.dll)
protected virtual void OnInvalidated(
	EventArgs e
)
You cannot use methods in XAML.

Parameters

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
{
    Solid,
    StyulusPoints
}


...


private DrawingMode strokeMode = DrawingMode.Solid;

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

     set
    {
        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();
        }
        else
        {
            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);
        }
    }
}

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

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

.NET Framework

Supported in: 3.5, 3.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.