Export (0) Print
Expand All

Stroke.OnInvalidated Method

Raises the Invalidated event.

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

Protected Overridable Sub OnInvalidated ( _
	e As EventArgs _


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
End Enum 'DrawingMode


Private strokeMode As DrawingMode = DrawingMode.Solid

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

        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 
        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()
            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 'DrawCore

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

© 2014 Microsoft