Alex Rivera | Logout

Delete all images added to canvas

Asked 2012-05-31T14:38:03.800
18

Is there a possible way to remove (delete) all images (children) added to a Canvas in C# (in WFP)?

Edit
Report

1 Answer

37

Do you mean you just want to remove all the child elements?

canvas.Children.Clear();

looks like it should do the job.

EDIT: If you only want to remove the Image elements, you can use:

var images = canvas.Children.OfType<Image>().ToList();
foreach (var image in images)
{
    canvas.Children.Remove(image);
}

This assumes all the images are direct child elements though - if you want to remove Image elements under other elements, it becomes trickier.

answered 2012-05-31T14:39:32.827

Your Answer