StrokeCollection.Draw Method (DrawingContext)

 

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
Available since 3.0
Return to top
Show: