Difference between Control Template and DataTemplate in WPF

Firoz picture Firoz · Aug 27, 2009 · Viewed 73.6k times · Source

What is difference between a ControlTemplate and a DataTemplate in WPF?

Answer

Matt Hamilton picture Matt Hamilton · Aug 27, 2009

Typically a control is rendered for its own sake, and doesn't reflect underlying data. For example, a Button wouldn't be bound to a business object - it's there purely so it can be clicked on. A ContentControl or ListBox, however, generally appear so that they can present data for the user.

A DataTemplate, therefore, is used to provide visual structure for underlying data, while a ControlTemplate has nothing to do with underlying data and simply provides visual layout for the control itself.

A ControlTemplate will generally only contain TemplateBinding expressions, binding back to the properties on the control itself, while a DataTemplate will contain standard Binding expressions, binding to the properties of its DataContext (the business/domain object or view model).