Stroke.OnInvalidated(EventArgs) 메서드

정의

Invalidated 이벤트를 발생시킵니다.

protected:
 virtual void OnInvalidated(EventArgs ^ e);
protected virtual void OnInvalidated(EventArgs e);
abstract member OnInvalidated : EventArgs -> unit
override this.OnInvalidated : EventArgs -> unit
Protected Overridable Sub OnInvalidated (e As EventArgs)

매개 변수

e
EventArgs

EventArgs 이벤트 데이터가 들어 있는 항목입니다.

예제

다음 예제에서는 속성에 Stroke 따라 StylusPoint 일련의 Mode 개체 또는 단색 스트로크로 그립니다. 이 예제에서는 메서드를 OnInvalidated 호출하여 스트로크가 DrawCore 그려지는 위치를 호출합니다.

// Enumerator that specifies the drawing mode of the stroke.
public enum DrawingMode
{
    Solid,
    StyulusPoints
}
' Enumerator that specifies the drawing mode of the stroke.

Public Enum DrawingMode
    Solid
    StyulusPoints
End Enum 'DrawingMode
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);
        }
    }
}
Private strokeMode As DrawingMode = DrawingMode.Solid

' Property that specifies whether to draw a solid stroke or the stylus points
Public Property Mode() As DrawingMode

    Get
        Return strokeMode
    End Get

    Set(ByVal value As DrawingMode)
        If strokeMode <> value Then
            strokeMode = value
            Me.OnInvalidated(New EventArgs())
        End If
    End Set

End Property


Protected Overrides Sub DrawCore(ByVal context As System.Windows.Media.DrawingContext, _
            ByVal overridedAttributes As DrawingAttributes)
    Dim strokeBrush As New SolidColorBrush(overridedAttributes.Color)

    ' If strokeMode it set to Solid, draw the strokes regularly.
    ' Otherwise, draw the stylus points.
    If strokeMode = DrawingMode.Solid Then
        Dim geometry As Geometry = GetGeometry(overridedAttributes)
        context.DrawGeometry(strokeBrush, Nothing, geometry)
        ' strokeMode == DrawingMode.StylusPoints
    Else
        Dim points As StylusPointCollection

        ' Get the stylus points used to draw the stroke.  The points used depends on
        ' the value of FitToCurve.
        If Me.DrawingAttributes.FitToCurve Then
            points = Me.GetBezierStylusPoints()
        Else
            points = Me.StylusPoints
        End If

        ' Draw a circle at each stylus point.
        Dim p As StylusPoint
        For Each p In points
            context.DrawEllipse(Nothing, New Pen(strokeBrush, 1), CType(p, Point), 5, 5)
        Next p
    End If

End Sub

설명

클래스에서 Stroke 상속하고 스트로크의 모양이 사용자 지정 상태를 기반으로 하는 경우 메서드를 OnInvalidated 호출하여 이벤트를 발생 Invalidated 시켜야 합니다. 이벤트를 InkPresenter 처리 Invalidated 하고 메서드를 호출합니다 DrawCore .

적용 대상