Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Why does linq not work directly against UIElementCollection?

$
0
0

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;

 


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>