I have the following class hierarchy (pseudocode):
BaseClass
DerivedClass1 : BaseClass
DerivedClass2 : BaseClass
I have a heterogeneous collection of BaseClass items that contains DerivedClass1 and DerivedClass2 items. When I bind this collection to a xamgrid and specify columns in xamgrid columns as following:
<ig:XamGrid x:Name="XamGrid_Mygrid" d:DataContext="{d:DesignInstance viewModel:BaseClassListViewModel,IsDesignTimeCreatable=False}" ItemsSource="{Binding PagedCollection}" AutoGenerateColumns="True"> <ig:XamGrid.Columns> <ig:TextColumn IsFixable="True" x:Name="Base Clas" Key="BaseClass" HeaderText="Base Class" /> <ig:TextColumn IsFixable="True" x:Name="Derived Clas" Key="DerivedClass" HeaderText="Derived Class" /> </ig:XamGrid.Columns> <ig:XamGrid.PagerSettings> <ig:PagerSettings AllowPaging="Bottom" /> </ig:XamGrid.PagerSettings> </ig:XamGrid>
I get runtime error saying that the Column called DerivedClass (which is present in DerivedClass1) is not found. What is a way around it?
Thanks!
Hello Andrew,
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.
Thanks Stefan. That did it.
Thank you for your post. I have been looking into it and I can say that the XamGrid is not designed to show heterogeneous data by default. The thing you can do is using UnboudColumns, because their keys don’t have to be names of a properties from the data source. I have created a sample project to show you this approach. I used a similar data structure to the one you described. Please let me know if this helps you or you have further questions on this matter.
Looking forward for your reply.