Trying to use LINQ against the Children property of a Canvas. Get error "could not find implementation of query pattern ... "
var ellipseList2 = from a in Canvas1.Children where a is Ellipse select a as Ellipse;
But I can "foreach" the items of the Children collection. I thought that means the Children collection has an IEnumerable interface.
foreach (var item in Canvas1.Children) { if (item is Ellipse) { } }
I see the solution is to use the OfType method of the Children collection to get an IEnumerable of the type. How does foreach work for a UIElementCollection and why it does not implement IEnumerable?
var ellipseList = from a in Canvas1.Children.OfType<Ellipse>( ) select a;