XAML - Use different template based on class

Total Post:128

Points:898
WPF 
WPF
 1259  View(s)
Ratings:
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")

       -Frequencies          

   -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

    Points:1019
    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.

Answer