This may be an obvious question, but I think there may well be multiple ways to implement it, so not only will this be useful to me, hopefully it will be useful to others.
Essentially I’m looking for the best way to implement a list view that can accept different types of objects and then renders them with the appropriate item/data template for that object.
So for example… we have a standard product list view, and when we view different categories the business has decided it would like to show a different item template style for each different category.
The main reason for asking this here, is to avoid a nasty hacky solution and discover a good clean method instead.
Hopefully I’ve provided enough information, let me know if you need more.
Just specifying
DataTemplatesin theResourceswith the respectiveDataTypeis enough, e.g.(Note that
DataTemplate.DataTypecan also be used for implicit XML data templating (see docs), the property type for that reason is notSystem.Type, so unlike inStyle.TargetTypeyou have to usex:Typeto reference a CLR-type. If you just enter a string it will not be converted to a type.)You might also want to look into
CompositeCollections, to get clean merged lists of varying types.Sample data i used: