• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1516
  • Last Modified:

ObservableCollection

Is it possible to convert an array to an ObservableCollection?
0
dchau12
Asked:
dchau12
  • 3
  • 2
1 Solution
 
tcullerCommented:
Easily done. I'll do an example using a collection of Doubles:
System.Collections.ObjectModel.ObservableCollection<System.Double> coll = new System.Collections.ObjectModel.ObservableCollection<System.Double>(nameOfArrayOfDoubles as System.Collections.IEnumerable<System.Double);

Open in new window

0
 
tcullerCommented:
Sorry, that's really crowded -- here:
System.Collections.ObjectModel.ObservableCollection<System.Double> coll
= new System.Collections.ObjectModel.ObservableCollection<System.Double>
(nameOfArrayOfDoubles as System.Collections.IEnumerable<System.Double);

Open in new window

0
 
dchau12Author Commented:
this works fine in WPF.  My issue is that silverlight does not have an observable collection that takes parameters.   So, assigning the values in the parameter "(nameOfArrayOfDoubles as System.Collections.IEnumerable<System.Double)"  is not possible.
0
 
tcullerCommented:
Hrm, I've never used Silverlight before. This question might do better in the Silverlight zone, then. I find it odd that Silverlight doesn't employ constructors, though...
0
 
dchau12Author Commented:
I looked into it further and confirmed that silverlight observable collections do not have constructors.  You have to instantiate your observable collection and then use a loop or aggregates to populate it with your objects.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now