OnInvalidated Method

Stroke.OnInvalidated Method

Raises the Invalidated event.

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

protected virtual void OnInvalidated (
	EventArgs e
)
protected void OnInvalidated (
	EventArgs e
)
protected function OnInvalidated (
	e : EventArgs
)
You cannot use methods in XAML.

Parameters

e

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 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2016 Microsoft