I found the solution to the problem.
I changed my converter to set the list property to another custom class which contains only one property of list type and wrote a hierarchical data template for the same.
PropertyToListConverter
public class PropertyToListConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
Type type = value.GetType();
PropertyInfo[] propertyList = value.GetType().GetProperties();
List<object> values =
(from property in propertyList
select GetValueOrElementName(value, property)).ToList();
return values;
}
private static object GetValueOrElementName(object value, PropertyInfo property)
{
var propVal = property.GetValue(value, BindingFlags.Default, null, null, CultureInfo.InvariantCulture);
if (property.PropertyType.IsGenericType && propVal != null)
{
Type type = property.PropertyType.GetGenericArguments().FirstOrDefault();
if (type == typeof(Child))
return new EnumerableClass() { Children = propVal as List<Child> };
}
if (propVal != null && !string.IsNullOrEmpty(propVal.ToString()))
return propVal;
return "Property["+ property.Name+"]";
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
CustomClass
public class EnumerableClass
{
public string Name { get; set; }
public List<Child> Children
{
get;
set;
}
}
Hierarchical Data template
<HierarchicalDataTemplate DataType="{x:Type en:Parent}"
ItemsSource="{Binding Converter={StaticResource ResourceKey=propertyToListConvertor}}">
<StackPanel Orientation="Horizontal">
<TextBlock Margin="0,4,0,0"
VerticalAlignment="Center"
FontWeight="Bold"
Text="{Binding Path=ParentName}" />
</StackPanel>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type ap:EnumerableClass}"
ItemsSource="{Binding Path=Children,UpdateSourceTrigger=PropertyChanged}">
<StackPanel Orientation="Horizontal">
<TextBlock Margin="0,4,0,0"
VerticalAlignment="Center"
FontWeight="Bold"
Text="Children" />
</StackPanel>
</HierarchicalDataTemplate>