I'm using SfTreeView to create an Exception explorer. When our application throws exceptions, they can be treelike in structure, and I want to be able to view them.
AggregateExceptions and CompositionExceptions have lists of children exceptions, and the SfTreeView works very well for them
However, the normal Exception uses the InnerException property, which is not a collection, and the HierarchyPropertyDescriptor cannot successfully bind to it. In a regular WPF TreeView, I can get around this with converters, but the HierarchyPropertyDescriptor does not expose a binding, just a string called ChildPropertyName.
Is there any way to make this work?
Here are the HierarchyPropertyDescriptors I am defining for my sfTreeView
<syncfusion:SfTreeView.HierarchyPropertyDescriptors>
<treeViewEngine:HierarchyPropertyDescriptor TargetType="{x:Type System:Exception}"
ChildPropertyName="InnerException" />
<treeViewEngine:HierarchyPropertyDescriptor TargetType="{x:Type System:AggregateException}"
ChildPropertyName="InnerExceptions" />
<treeViewEngine:HierarchyPropertyDescriptor TargetType="{x:Type Composition:CompositionException}"
ChildPropertyName="RootCauses" />
</syncfusion:SfTreeView.HierarchyPropertyDescriptors>
I have bolded the line of XAML that doesn't work
Thanks for the response. Just to elaborate, I can show nested exceptions with the WPF TreeView with a converter like this:
<HierarchicalDataTemplate ItemsSource="{Binding InnerException, Converter={StaticResource ObjectToCollectionConverter}}" DataType="{x:Type System:Exception}">
<TreeViewItem Header="{Binding Converter={StaticResource ObjectToTypeConverter}}" />
</HierarchicalDataTemplate>
result:
the converter:
public class ObjectToCollectionConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if(value is null)
{
return null;
}
return new object[] { value };
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
I can use the same approach for Syncfusion's TreeViewAdv as well, since it also uses the HierarchicalDataTemplate:
Hi Benjamin,
As we mentioned in our previous update, we are validating your requirement and will update further details on February 1, 2022.
We appreciate your patience until then.
Regards,
Sampath Narayanan.S
Thank you!
I've attached a sample solution.
Here is the full TreeViewAdv xaml that works:
<syncfusion:TreeViewAdv ItemsSource="{Binding Exception, Converter={StaticResource ObjectToCollectionConverter}}">
<syncfusion:TreeViewAdv.Resources>
<HierarchicalDataTemplate ItemsSource="{Binding InnerException, Converter={StaticResource ObjectToCollectionConverter}}"
DataType="{x:Type System:Exception}">
<TreeViewItem Header="{Binding Converter={StaticResource ObjectToTypeConverter}}" />
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type System:AggregateException}"
ItemsSource="{Binding InnerExceptions}">
<TreeViewItem Header="{Binding Converter={StaticResource ObjectToTypeConverter}}" />
</HierarchicalDataTemplate>
</syncfusion:TreeViewAdv.Resources>
</syncfusion:TreeViewAdv>Hi Benjamin,
We are checking the possibilities to achieve the requirement in SfTreeView. We will update you with more details on February 4, 2022.
Regards,
Sampath Narayanan.S
Hi Benjamin,
We are still checking the possibilities to achieve the requirement in SfTreeView. We will update you with more details on February 9, 2022.
Regards,
Sampath Narayanan.S
Thanks for the reply!
This will work. Thanks!
Ben