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 DataTemplate
s. When would ContentPresenter
be a better choice? and why?
6 Answers
ContentControl
is a base class for controls that contain other elements and have a Content
-property (for example, Button
).
ContentPresenter
is used inside control templates to display content.
ContentControl
, when used directly (it's supposed to be used as a base class), has a control template that uses ContentPresenter to display it's content.
My rules of thumb (not applicable in every case, use your judgment):
- Inside
ControlTemplate
useContentPresenter
- Outside of
ControlTemplate
(includingDataTemplate
and outside templates) try not to use any of them, if you need to, you must preferContentPresenter
- Subclass
ContentControl
if you are creating a custom "lookless" control that host content and you can't get the same result by changing an existing control's template (that should be extremely rare).

- 178,213
- 47
- 333
- 501

- 29,306
- 10
- 67
- 103
-
1Does 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? – Wilka Aug 17 '09 at 21:05
-
I've edited the answer with more details when I would use ContentPresenter and when ContentControl – Nir Aug 18 '09 at 08:44
-
2Ok I got idea that ContentPresenter should be used in templates instead of ContentControl, but why? – sll Jul 22 '11 at 13:00
-
36@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) – Nir Jul 22 '11 at 21:26
-
Pretty nice explanation you can find here: http://charly-studio.com/blog/contentcontrol-vs-contentpresenter/ – peter70 Jul 11 '14 at 08:22
-
33ContentPresenter 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. – user195275 Oct 10 '14 at 15:11
-
I'm a little late to the party here. Great explanation @sll, Thanks!!!. I generally think of ContentPresenter like this: If the control using your template has a Content property (i.e. is a ContentControl), then the content you specify in your control will be presented at the location where ContentPresenter is located in your template. – KyleLib May 18 '17 at 21:58
ContentPresenter is usually used in a ControlTemplate, as a placeholder to say "put the actual content here".
A ContentControl can be used anywhere, not necessarily in a template. It will pick up any DataTemplate defined for the type of content assigned to it

- 286,951
- 70
- 623
- 758
-
7Wouldn't a ContentPresenter also cause a DataTemplate to be applied to it's content? Isn't that one of its primary purposes? – Drew Noakes Aug 17 '09 at 14:08
-
1mmm... yeah, probably. Anyway, Bea Stollnitz's explanation is much better than mine ;) – Thomas Levesque Aug 17 '09 at 14:39
-
2Your succinct answer seemed to sum it up quickly: I believe the whole design of the ContentPresenter is to simply "implement" the DataTemplate inflation --- it seems to have the sole job of just locating and inflating the template, setting the DataContext too; and trying then to just "disappear" as much as possible (THOUGH you STILL can bind within the inflated template to ambient properties like TextElement properties, coming then from the ContentPresenter). You don't need to worry about other things, and it just inflates the template in a relatively slim way. (I'm looking for the slimmest!) – Steven Coco Sep 19 '18 at 09:33
I recently wrote a post on my blog regarding these two controls:
ContentPresenter vs ContentControl
The ContentPresenter.ContentSource is what actually makes the biggest difference between the two classes.
ContentSource property makes sense only within a ControlTemplate; it determines which TemplatedParent property the content should be mapped with.
For example, if a control contains a dependency property MyProperty1
, then we might find the following within its ControlTemplate
:
<ControlTemplate TargetType="MyControl" >
[...]
<ContentPresenter ContentSource="MyProperty1" />
[...]
</ControlTemplate>
The content of the ContentPresenter will receive the value of MyProperty1
.
Please note that if the name of the property is Content
, there is no need to specify ContentSource
as it is the default value.
For those who know angularJs: this is similar to transclude mecanism.

- 28,293
- 19
- 112
- 138

- 1,934
- 16
- 28
Its an old question but I was just finishing developing an animated Tile Control, template based for a universal app, look at this code from the old Phone WP7/8 SDK:
<ContentControl x:Name="contentControl" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalAlignment="Stretch" VerticalContentAlignment="Stretch">
<ContentPresenter x:Name="contentPresenter" CacheMode="BitmapCache"/>
</ContentControl>
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.

- 718
- 9
- 20
ContentControl
is to make a WPF custom control (dont mix up with user control). So it is your top-level class. ContentPresenter
is just like any other "regular" control. You can use it in custom or user control or in a template or just in markup

- 9,613
- 13
- 72
- 151
Sometimes an example is easier than theoretical jargon. In an MS web site (Scroll to the bottom: http://msdn.microsoft.com/en-us/library/system.windows.controls.contentpresenter(v=vs.110).aspx), it uses a button as an example. A Button has a ContentControl, which allows you to place one control or a custom control that could be an Image, Text, CheckBox, StackPanel, Grid, whatever.
After the customization of Button, now on the Xaml, you can write
<my:Button>
<my:Button.Content>
<my:AnotherControl>
</my:Button.Content>
</my:Button>
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.

- 3,689
- 2
- 28
- 28
-
2A [`Button`](http://msdn.microsoft.com/en-us/library/system.windows.controls.button%28v=vs.110%29.aspx) does not *have* a [`ContentControl`](msdn.microsoft.com/en-us/library/system.windows.controls.contentcontrol(v=vs.110).aspx), it *is a* (inherits from) `ContentControl`. The `Button` *has* a [`ContentPresenter`](http://msdn.microsoft.com/en-us/library/system.windows.controls.contentpresenter%28v=vs.110%29.aspx). Note that you can do that with the standard `Button`, no need to customize it. – O. R. Mapper Nov 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. Mapper Nov 19 '14 at 18:54