Samuele Dassatti
Samuele Dassatti

Reputation: 269

Clear an InkCanvas [UWP]

I want to add a button to my UWP app that removes all the strokes from an InkCanvas, but the suggested method inkCanvas.InkPresenter.Strokes.Clear() isn't recognized as a valid command, is it obsolete or I am doing something else wrong?

Upvotes: 1

Views: 3011

Answers (3)

micheljr
micheljr

Reputation: 11

This works for me on buttonclick:

YourCanvasName.Strokes.Clear()

Upvotes: 1

Prabhdeep Singh
Prabhdeep Singh

Reputation: 306

Nothing really worked until I coded this out: This is on button click btw.

YourWindow.xaml.cs

private void ClearBtn_click(object sender, RoutedEventArgs e)
        {
            if(YourInkCanvaName.Strokes.Count != 0)
            {
                while (YourInkCanva.Strokes.Count > 0)
                {
                    draw.Strokes.RemoveAt(draw.Strokes.Count - 1);
                }
            }
            else
            {
                // DO NOTHING WHEN THERE IS NOTHING TO CLEAR
            }
            
        }

Upvotes: 0

Justin XL
Justin XL

Reputation: 39006

Try inkCanvas.InkPresenter.StrokeContainer.Clear();.

Upvotes: 5

Related Questions