What would be the best way to do ViewModel from an xml like:
<Cars>
<Car>
<Name/>
<Model/>
<Parts>
<Part>
<PartName/>
<PartType/>
</Part>
<Part>
<PartName/>
<PartType/>
</Part>
</Parts>
</Car>
</Cars>
would it be like
public class PartViewModel : INotifyPropertyChanged
{
private string _PartName;
private string _PartType;
//... and proper get/seters for NotifyPropertyChanged
};
public class CarViewModel : INotifyPropertyChanged
{
private string _Name;
private string _Model;
private ObservableCollection<PartViewModel> _parts;
//... and proper get/seters for NotifyPropertyChanged
};
then how would LINQ look like to fill CarViewModel ?
List<CarViewModel> FeedItems = (from carsXdoc in xdoc.Descendants("Cars")
select new CarViewModel()
{
Name = carsXdoc.Element("Name").Value,
Model = carsXdoc.Element("Model").Value,
// And then ? how do you fill nested observable collection with parts ?
}).ToList();
Something like following should do the trick:
ToObservableCollection()method: