StrokeCollection.Replace Method (StrokeCollection, StrokeCollection)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Replaces the specified StrokeCollection with a new StrokeCollection.

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

public void Replace(
	StrokeCollection strokesToReplace,
	StrokeCollection strokesToReplaceWith


Type: System.Windows.Ink.StrokeCollection

The destination StrokeCollection.

Type: System.Windows.Ink.StrokeCollection

The source StrokeCollection.

Exception Condition

strokesToReplace is empty.


strokesToReplaceWith is empty.


A Stroke in strokesToReplaceWith is already in strokesToReplace.


The strokes in strokesToReplaceWith are not continuous.

The Replace method raises the StrokesChanged event for each Stroke it replaces.

The following example demonstrates how to replace the selected strokes on an InkCanvas with another StrokeCollection. This example assumes that there is an InkCanvas called inkCanvas1.

// Replace the selected strokes with other strokes.
private void ReplaceStrokes(StrokeCollection strokes)
    StrokeCollection selectedStrokes = inkCanvas1.GetSelectedStrokes();

    if (selectedStrokes != null && selectedStrokes.Count > 0)
        inkCanvas1.Strokes.Replace(selectedStrokes, strokes);

.NET Framework
Available since 3.0
Return to top