4

Can someone elaborate the difference between ControlTemplate and DataTemplate in wpf?

What should one use in case of custom controls? Like for example a StackPanel which possibly has an image and a TextBox?

It seems confusing in some cases where you define a custom control using the 'Content' property.

It would be great if an example of how each can be used in different scenarios can be provided.

akjoshi
  • 15,374
  • 13
  • 103
  • 121
Archie
  • 2,564
  • 8
  • 39
  • 50
  • 3
    possible duplicate of http://stackoverflow.com/questions/1340108/differnce-between-control-template-and-datatemplate-in-wpf – Matt Hamilton Apr 28 '10 at 05:11

1 Answers1

10

A ControlTemplate is used to change the look of an existing control. So if you don't want your buttons to look rectangular, you can define a control Template which makes them look oval or any irregular shape. It's a way to customize 'look-less' stock WPF controls ; an alternative to writing your own user-controls. More details

A DataTemplate is used to specify how an instance of a specific class (usually a Data Transfer object - an object with properties) is to be rendered visually. e.g. define a DataTemplate to visualize a Customer instance in a listbox displaying all customers. More details

akjoshi
  • 15,374
  • 13
  • 103
  • 121
Gishu
  • 134,492
  • 47
  • 225
  • 308