How to create an ObservableCollection using LINQ in Silverlight

Posted by sonofpirate on Stack Overflow See other posts from Stack Overflow or by sonofpirate
Published on 2010-04-22T15:37:59Z Indexed on 2010/04/22 15:43 UTC
Read the original article Hit count: 832

Filed under:
|

In a non-Silverlight world, it is easy to use LINQ to create an ObservableCollection. This is because the ObservableCollection class has constructors that accept any IEnumerable<T> or List<T>. However, the Silverlight version does not! This means that code such as:

var list = (from item in e.Result
            select new ViewModel(item)).ToList();

Items = new System.Collections.ObjectModel.ObservableCollection<ViewModel>(list);

will not work in Silverlight.

Is there another option to make this work besides resorting to a for-each statement?

© Stack Overflow or respective owner

Related posts about Silverlight

Related posts about LINQ