Question

I want to create something like a TreeView with the ListView Control. There are two classes with the same base-class like this:

public abstract class DataObjectBase
{
    public string Name { get; set; }

    public override string ToString()
    {
        return this.Name;
    }
}

public class SimpleDataObject : DataObjectBase
{
    public object Value { get; set; }
}

public class ComplexDataObject : DataObjectBase
{
    private ObservableCollection<DataObjectBase> _DataObjects = new ObservableCollection<DataObjectBase>();

    public ObservableCollection<DataObjectBase> DataObjects
    {
        get { return _DataObjects; }
        set { _DataObjects = value; }
    }
}

How can I bind this structure to a ListView using a HirarchicalDataTemplate? The complex DataObject can have n subelements in the _DataObjects ObservableCollection.

Was it helpful?

Solution

The answer is ... you don't. If ou look at the documentation http://msdn.microsoft.com/en-us/library/system.windows.hierarchicaldatatemplate(v=vs.110).aspx HierarchicalDataTemplates can only be used with HeaderedItemsControls. The ListView inherits from simple ItemsControl.

You can either use a TreeView or use classic DataTemplates to implement it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top