Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
60
Xamgrid and heterogeneous collections
posted

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!

Parents
  • 138253
    Verified Answer
    Offline posted

    Hello Andrew,

     

    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.

    XamGridUnboudColumns.zip
Reply Children
No Data