What is difference between a ControlTemplate
and a DataTemplate
in WPF?
Wpf – Difference between Control Template and DataTemplate in WPF
controltemplatedatatemplatewpf
Related Topic
- .net – In WPF, what are the differences between the x:Name and Name attributes
- Wpf – the difference between a User Control Library and a Custom Control Library
- Wpf – Difference between Visibility.Collapsed and Visibility.Hidden
- R – WPF DataTemplate/ControlTemplate and VS2008 designer
- .net – The difference between ListBox and ListView
- Wpf – Difference between SelectedItem, SelectedValue and SelectedValuePath
Best Answer
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. AContentControl
orListBox
, 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 aControlTemplate
has nothing to do with underlying data and simply provides visual layout for the control itself.A
ControlTemplate
will generally only containTemplateBinding
expressions, binding back to the properties on the control itself, while aDataTemplate
will contain standard Binding expressions, binding to the properties of itsDataContext
(the business/domain object or view model).