从 xml 执行 ViewModel 的最佳方法是什么,例如:
<Cars>
<Car>
<Name/>
<Model/>
<Parts>
<Part>
<PartName/>
<PartType/>
</Part>
<Part>
<PartName/>
<PartType/>
</Part>
</Parts>
</Car>
</Cars>
会不会像
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
};
那么 LINQ 会如何填充 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();