I'm using a TreeView along with a HierarchicalDataTemplate to display a Hierarchical listing returned from a webservice. Depending on search criteria, this listing can get to be very long and several nested levels deep. It would be useful to display a "map" of sorts to the user so that they can see where in this listing they are relative to the top level. The model used to create the hierarchy looks like this:
public class IndexEntry
{
public int Score { get; set; }
//More properties that define attributes of this class
//Child objects of the hierarchy are stored in this property
public List<IndexEntry> SubEntries { get; set; }
}
As you can see, the hierarchy is built using a List of IndexEntry types.
The ViewModel looks like this:
public class IndexEntriesViewModel
{
//TreeView ItemsSource is bound to this collection
public ObservableCollection<IndexEntry> IndexList { get; set; }
//More properties to define the ViewModel
}
As you can see, the TreeView's ItemsSource would be bound to the ObservableCollection of IndexEntry types. I don't see any obvious way to access the parent object as things are now. I am considering the option of adding another property in the model that would point directly to the parent object of that particular entry. This would ultimately allow me to walk up & down the hierarchy and grab what I like as I need it.
So, the question is - Can anyone think of a better way to accomplish this? Is there a property in the TreeView itself that I'm missing that will provide this ability?