My apologies for not posting the rest of the code. I thought that just the XAML would suffice.
In any case, here's the class I am using for the TreeView:
public class PartsList { public long PartsListID { get; set;} public long? PartID { get; set;} public long? VendorID { get; set;} public string VendorName { get; set;} public string VendorPartNo { get; set;} public string VendorPartNoLink { get; set;} public double? Price { get; set;} public string Alternative { get; set;} public string AlternativeLink1 { get; set;} public string AlternativeLink2 { get; set;} public string AlternativeLink3 { get; set;} public string Description { get; set;} public virtual StockControl StockControl { get; set;} }
In the ViewModel:
public class StockItemsViewModel : BindableBase { private ObservableCollection<PartsList> _currentPartList; private DBContext _context = new DBContext(); public ObservableCollection<PartsList> CurrentPartsList { get {return _currentPartList;} set { SetProperty(ref _currentPartList, value); } } // code snipped public StockItemsViewModel() { if (!DesignerProperties.GetIsInDesignMode(new System.Windows.DependencyObject())) { // code snipped CurrentPartsList = new ObservableCollection<PartsList>(CurrentItem.PartsLists.ToList()); } } // code snipped private void ChangeList(long ID) { _currentPartList.Clear(); CurrentPartsList.AddRange(_context.PartsLists.Where(p => p.PartID == ID).ToList()); } }
}
As you can see, it's just a simple POCO class that Entity Framework created which is the actual table in SQL Server 2008. And as you can see, I'm just using ONE class on the TreeView. BindableBase is a class basically implements the INPC where the SetProperty uses the [CallMemberName] to fire the PropertyChanged event.
I think the second one would work, but now that you seen more of the code, I do appreciate your thoughts and opinions on how I should solve the problem with the child leaves.