What is difference between a ControlTemplate
and a DataTemplate
in WPF?
Very basically a ControlTemplate
describes how to display a Control while a DataTemplate
describes how to display Data.
For example:
A Label
is a control and will include a ControlTemplate
which says the Label
should be displayed using a Border
around some Content (a DataTemplate
or another Control).
A Customer
class is Data and will be displayed using a DataTemplate
which could say to display the Customer
type as a StackPanel
containing two TextBlocks
one showing the Name and the other displaying the phone number. It might be helpful to note that all classes are displayed using DataTemplates
, you will just usually use the default template which is a TextBlock
with the Text
property set to the result of the Object's ToString
method.