There is a Canvas, for it there are several child Image objects with the registered Uid / Name. Is it possible to find the specified Uid / Name from the bihind code and delete them from the Canvas?

  • Why not MVVM? - VladD

1 answer 1

If you need to delete 1 element, then you can try something by type:

var image = canvas1.Children.OfType<Image>().FirstOrDefault(x=>x.Name == "Image1"); //В нашем canvas (c именем canvas1) находим объект типа Image с именем Image1. canvas1.Children.Remove(image); //Удаляем из canvas1 дочерний элемент, найденный ранее. 

You can take all the elements from canvas1 , convert them to a List and walk through the children in a loop:

 var images = canvas1.Children.OfType<Image>().ToList(); //Все элементы типа Image в нашем подопытном canvas1 foreach (var image in images) { if (image.Name == "Image1") //Соответствие на имя. canvas1.Children.Remove(image); //Удаляем }