Convert List<T> to ObservableCollection<T> in WP7

Josh Close picture Josh Close · Apr 6, 2011 · Viewed 108k times · Source

I don't know if it's just too late or what, but I don't see how to do this...

What I'm expecting to do, and what the object browser says is there, is this:

var oc = new ObservableCollection<T>( new List<T>() );

But ObservableCollection<T> has a single parameterless constructor. The object browser says there is 2 overloads where List and IEnuerable should be able to be passed in.

Is there something wrong with my setup? Are the constructors not on the phone version? (that would be strange)

If this really doesn't exist, what is the standard way of doing this with WP7 now?

Answer

eugene.sushilnikov picture eugene.sushilnikov · Apr 25, 2013

ObservableCollection has several constructors which have input parameter of List<T> or IEnumerable<T>:
List<T> list = new List<T>();
ObservableCollection<T> collection = new ObservableCollection<T>(list);