I'm not sure when I should use ContentPresenter instead of ContentControl (and vice-versa). At the moment, I'm using ContentControl pretty much all the time in my DataTemplates. When would ContentPresenter be a better choice? and why?

Does that mean that, in general, I should probably use ContentPresenter inside my DataTemplates, because it's more light-weight (but functionally equivalent when used in a DataTemplate like this)? Then just use ContentControl as a base class if I'm writing a new control?
–
WilkaAug 17 '09 at 21:05

I've edited the answer with more details when I would use ContentPresenter and when ContentControl
–
NirAug 18 '09 at 8:44

1

Ok I got idea that ContentPresenter should be used in templates instead of ContentControl, but why?
–
sllJul 22 '11 at 13:00

21

@sll - ContentControl is the base class for every control that displays "content" (example: Label), ContentPresenter is the code used internally by ContentControl to display the content - so: 1. ContentPresenter is more lightweight, 2. ContentPresenter is designed to be used inside control templates and 3. ContnetPresenter is designed to be used as-is while ContentControl is designed to be extended (inherited from)
–
NirJul 22 '11 at 21:26

1

ContentPresenter behaves differently from ContentControl when it comes to having the Content property set. When you set ContentPresenter's Content property its DataContext changes to match the Content property, but ContentControl's DataContext remains unaffected. This matters if you have other properties on ContentPresenter set via binding, because once DataContext changes, all bindings use that as the source.
–
user195275Oct 10 '14 at 15:11

The ContentPresenter.ContentSource is actualy what makes the biggest difference between the 2 classes.
ContentSource property has sense only in a ControlTemplate, it determines which TemplatedParent property the content should be mapped with.
for example, if a control contains a dependency property MyProperty1, then in its ControlTemplate we might find somewhere:

In the above example code, the "my:Button.Content" is the ContentControl. The AnotherControl will be place to what you had specified where the ContentPresenter is.

Similarly, when compares TextBox and TextBlock, TextBox has a ContentPresenter for you to stuff stuff in it just like the above Button example whereas a TextBlock doesn't. A TextBlock only allows you to enter text.

A Button does not have a [ContentControl](msdn.microsoft.com/en-us/library/system.windows.controls.cont‌​entcontrol(v=vs.110).aspx), it is a (inherits from) ContentControl. The Buttonhas a ContentPresenter. Note that you can do that with the standard Button, no need to customize it.
–
O. R. MapperNov 19 '14 at 18:53

But unrelated to that, this answer does not explain whether and why, instead of the ContentPresenter, a ContentControl could not be used just as well in the ControlTemplate to display the content of the Button. As such, it does not answer the question.
–
O. R. MapperNov 19 '14 at 18:54

Here you can see the ContentControl is the Container and the Presenter for displaying content. In most cases the ControlTemplate will be the Container but if you want in your ControlTemplate another container you can put an extra Container: ContentControl in it and for presenting the content a separate ContentPresenter. If you dont need a separate container then just use ControlTemplate and ControlPresenters for displaying content blocks at least thats what the guys at Microsoft did when they developed the WP7/8 SDK. The ContentControl can also be used for displaying content but then it serves both as container and presenter. So in the sample code above its purpose is splitted in Container and Presenter. In dynamic samples you could display the container (it can have an empty background or something thats not there yet) and then dynamically fill it with the presenter content. A container has dimensions (width,height etc.), you put those properties on the container control and present content on it. In the sample the ContentControl determines what has to be done with the presenter content.