Difference between Control Template and DataTemplate in WPF

前端 未结 7 1468
孤城傲影
孤城傲影 2020-12-07 07:13

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

相关标签:
7条回答
  • 2020-12-07 08:03

    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.

    0 讨论(0)
提交回复
热议问题