Clone a UIElementCollection

To clone a Silverlight UIElementCollection there’s no clone methods. We can’t also create a new UIElementCollection object, ‘cause default constructor is unavailable: if you try the error appears:

is inaccessible due to its protection level

And we can’t create a “building” loop.

Solution

The solution is to use a Generic List, List<T>:

List<UIElement> contentBk = new List<UIElement>();
foreach (UIElement u in this.Children)
{
contentBk.Add(u);
}

Game over 🙂

Loading Facebook Comments ...

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *