XAML - Use different template based on class

Total Post:128

 1210  View(s)
Rate this:

I have a nested datagrid. The grid is bound to a EquipmentListViewModel, which then contains a list of EquipmentViewModels. Each row can be dropped down by clicking a "+" button which will display a list of Frequencies for that equipment. I want to be able to display different RowDetailsTemplates depending on the CLASS of the row. The following is an example of what I want to do:

 -BaseClass(Hit + button to dropdown equipment list below)

   -EquipmentTypeA(Should have a + button to drop down, is of class "TypeA")


   -EquipmentTypeB(Doesnt contain a + buton, so it is different than EquipmentTypeA, of class "TypeB")

How can I have BaseClass contain a list of EquipmentTypes, where each row implements a derived class from the EquipmentTypes base class(TypeA,TypeB,etc). This way I can have each row have custom code depending on its class type(if it should contain a button, etc).

  1. Post:145

    Re: XAML - Use different template based on class

    Hi Ashish,

    Instead of specifying RowDetailsTemplates explicitly, just make sure that the visual tree contains a DataTemplate for each class (EquipmentTypeA and EquipmentTypeB) you wish to display. These will get used by default if the template is not specified.



Enter your email address here always to be updated. We promise not to spam!