The DataTemplateSelector provides a way to apply data templates based on custom logic.
Typically, you use a template selector when you have more than one data template defined for the same type of objects. For example, use it if your binding source is a list of student objects and you want to apply a particular template to the part-time students. You can do this by creating a class that inherits from DataTemplateSelector and by overriding the SelectTemplate() method. Once your class is defined you can assign an instance of the class to the template selector property of your element.
For more information, you can check the DataTemplateSelector Class msdn article.