Children that are single items instead of collections

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


11 Replies 1 reply marked as answer

MA Mohanram Anbukkarasu Syncfusion Team January 27, 2022 02:24 PM UTC

Hi Benjamin, 

We are currently validating your requirement. We will update further details on February 1, 2022. We appreciate your patience until then.  

Regards, 
Mohanram A. 





BW Benjamin Wendt January 27, 2022 03:23 PM UTC

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:
Capture.PNG


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:

Capture.PNG



SS Sampathnarayanan Sankaralingam Syncfusion Team January 28, 2022 12:02 PM UTC

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



SS Sampathnarayanan Sankaralingam Syncfusion Team February 1, 2022 02:38 PM UTC

Hi Benjamin,  

We have checked about your requirement in SfTreeView and found that the HierarchyPropertyDescriptor is not bind to it since the InnerException is not a collection. However can you please provide the sample which created with the Treeview/TreeViewAdv which will be more helpful to us to find a possibilities to achieve the same in SfTreeView. 

Regards, 
Sampath Narayanan.S 



BW Benjamin Wendt February 1, 2022 03:20 PM UTC

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>

Attachment: ExceptionViewing_268a3141.zip


SS Sampathnarayanan Sankaralingam Syncfusion Team February 2, 2022 01:58 PM UTC

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



SS Sampathnarayanan Sankaralingam Syncfusion Team February 7, 2022 02:36 PM UTC

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



BW Benjamin Wendt February 7, 2022 02:47 PM UTC

Thanks for the reply!



MA Mohanram Anbukkarasu Syncfusion Team February 9, 2022 02:29 PM UTC

Hi Benjamin,
In SfTreeView the value set for the ItemSource and the ChildPropertyName must be a collection. So, you can achieve your requirement to create Exception explorer for normal Exception only by creating a custom model class with properties to have exception related details line Message, InnerException collection(which can be used to populate inner exception) and a collection of that model should be used as ItemsSource for the SfTreeView. It can be done by using converter to convert the Exception into a collection of custom model class. We have modified the provided sample using SfTreeView and it is available in the following link for your reference.  


Please have a look at this sample and let us know if you have any concerns.  

Regards, 
Mohanram A. 



Marked as answer

BW Benjamin Wendt February 9, 2022 03:39 PM UTC

This will work.  Thanks!


Ben



MA Mohanram Anbukkarasu Syncfusion Team February 10, 2022 04:49 AM UTC

Hi Benjamin,  

We are glad to know that the provided solution works for you. Please let us know if you require any other assistance from us.  

Regards, 
Mohanram A. 




Loader.
Up arrow icon