I create a class ReportNode, it uses the NodeTag property to store the actual record that is used to populate the treenode
public class ReportNode : ViewModelBase
{
public ReportNode(string sLabel, object oObject, string sColor)
{
NodeLabel = sLabel;
NodeTag = oObject;
Color = sColor;
}
public string NodeLabel { get; set; }
public object NodeTag { get; set; }
public string Color { get; set; }
private ObservableCollection<ReportNode> \_ChildNodes;
public ObservableCollection<ReportNode> ChildNodes
{
get
{ return \_ChildNodes; }
set
{
\_ChildNodes = value;
base.OnPropertyChanged("ChildNodes");
}
}
}
Hierarchical data template binds the itemssource to the ChildNodes collection. When loading the nodes I stuff the NodeLabel with the text to display and the list object goes in the NodeTag property. When accessing the node I test the typeof the nodetag to determine what to do with the node. I have 1 tree with 6 different data sources, works perfectly.
Never underestimate the power of human stupidity RAH