Ler en inglés

Compartir por


Stroke.OnInvalidated(EventArgs) Método

Definición

Genera el evento Invalidated.

C#
protected virtual void OnInvalidated(EventArgs e);

Parámetros

e
EventArgs

Objeto EventArgs que contiene los datos del evento.

Ejemplos

En el ejemplo siguiente se dibuja como Stroke un trazo sólido o como una serie de StylusPoint objetos, según la Mode propiedad . En el ejemplo se llama al OnInvalidated método , que a su vez llama al DrawCore donde se dibuja el trazo.

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);
        }
    }
}

Comentarios

Si hereda de la Stroke clase y la apariencia del trazo se basa en un estado personalizado, debe llamar al OnInvalidated método para generar el Invalidated evento. InkPresenter controla el Invalidated evento y llama al DrawCore método .

Se aplica a

Produto Versións
.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