Export (0) Print
Expand All

StrokeCollection.Draw Method

Draws the strokes in the StrokeCollection.

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

public void Draw(
	DrawingContext context
)

Parameters

context
Type: System.Windows.Media.DrawingContext
The DrawingContext on which to draw the StrokeCollection.

The following example creates a custom element that displays a thumbnail view of an InkCanvas. The custom element keeps a reference to an InkCanvas and redraws itself when the StrokeCollected event occurs.


public class InkThumbnail : FrameworkElement
{
    private InkCanvas sourceInkCanvas = null;

    // Get the InkCanvas that the user draws on.
    public InkCanvas Source
    {

        get 
        { 
            return sourceInkCanvas; 
        }

        set
        {

            if (sourceInkCanvas != null)
            {
                // Detach the event handler from the former InkCanvas.
                sourceInkCanvas.StrokeCollected -= new InkCanvasStrokeCollectedEventHandler(SourceChanged);
            }

            sourceInkCanvas = value;


            if (sourceInkCanvas != null)
            {
                // Attach the even handler to the InkCannvas
                sourceInkCanvas.StrokeCollected += new InkCanvasStrokeCollectedEventHandler(SourceChanged);
            }

        }
    }

    // Handle the StrokeCollection event of the InkCanvas.
    private void SourceChanged(object sender, InkCanvasStrokeCollectedEventArgs e)
    {

        // Cause the thumbnail to be redrawn.
        this.InvalidateVisual();
    }


    protected override void OnRender(DrawingContext drawingContext)
    {

        base.OnRender(drawingContext);

        // Draw the strokes from the InkCanvas at 1/4 of their size.
        drawingContext.PushTransform(new ScaleTransform(0.25, 0.25));

        if (sourceInkCanvas != null)
        {
            sourceInkCanvas.Strokes.Draw(drawingContext);
        }
    }


}


.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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

Community Additions

ADD
Show:
© 2014 Microsoft