I'm trying to determine the best way to accomplish binding a Collection of a custom class to a TreeView.
I currently have two custom classes, one held in a Collection, and one held in a Collection inside the first class:
Collection<Device> _devices = new Collection<Device>();
class Device
{
public ulong DeviceID { get; private set; }
private List<Capability> _capabilities = new List<Capability>();
public string FriendlyName{ get; set; }
public Capability AddCapability(Capability capability)
{
_capabilities.Add(capability);
return capability;
}
public List<Capability> GetCapabilities()
{
// not safe yet
return _capabilities;
}
}
abstract class Capability
{
public uint CapabilityIndex { get; private set; }
public string FriendlyName{ get; set; }
}
I'm trying to get a TreeView to display the collection of devices which when expanded lists the capabilities.
Options I've considered include:
- looping through and creating TreeNode objects from the data I want to display (but I'm not sure how is best to refer back to the original object when selected)
- inheriting from the TreeNode class but this feels ugly as I'm storing the same data in multiple places (and most of the time I don't need them as TreeNodes so it feels like a waste of resources)
Any suggestions?