Olvasás angol nyelven Szerkesztés

Megosztás a következőn keresztül:


Stroke.OnInvalidated(EventArgs) Method

Definition

Raises the Invalidated event.

C#
protected virtual void OnInvalidated(EventArgs e);

Parameters

e
EventArgs

An EventArgs that contains the event data.

Examples

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.

C#
// Enumerator that specifies the drawing mode of the stroke.
public enum DrawingMode
{
    Solid,
    StyulusPoints
}
C#
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);
        }
    }
}

Remarks

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.

Applies to

Termék Verziók
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10