I'd like to create a re-usable ListView with rows of any or all of:
Labels + textboxes or Labels + Comboboxes or Labels + DatePickers
using Templates. I still do not understand Templates too well and would like to know which of them - ControlTemplate, DataTemplate, ItemsTemplate or ContentTemplate - to use for this and how. Thanks!
There are 2 different types of templates:
DataTemplateandControlTemplate.ControlTemplateis used on theTemplateproperty of classes derived fromControland defines the visual tree for a specific type of control.Pretty much any other place that templates show up is using
DataTemplate. This includesContentTemplateandItemTemplateproperties.DataTemplatesdefine a visual tree for any non-Visual data type. When the template is rendered itsDataContextis the data object being rendered (i.e. aList<T>item) making it easy to bind data properties.To mix templates for different types in a single list you can use a
DataTemplateSelectorwhich allows you to write code to pick a template for each item. The other option is to create multiple implicit templates (DataTypebut nox:Key) for the different CLR types of objects in the list. As long as those templates are in the resource scope of the control rendering the collection the types will resolve their templates automatically.