Basically, I don't understand what the real difference here is:
The Microsoft code for TabItem uses:
<ContentPresenter ContentSource="Header" ... />
So, when would one use the Content
property instead of (or in addition to) ContentSource
?
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.
In WPF Content Presenter is a control that displays a single piece of content. In WPF Content Presenter is a control that displays a single piece of content. CONTENT PRESENTER: Content Presenter in WPF is used inside control templates, as well as inside the root application markup.
This property should only be used when the ContentPresenter is in a template. When a template contains a ContentPresenter with ContentSource set to "Abc", the Content, ContentTemplate, and ContentTemplateSelector properties of the ContentPresenter are automatically aliased to Abc, AbcTemplate, and AbcTemplateSelector, respectively. Beginning with the .NET Framework version 3.5 Service Pack 1, setting ContentSource to "Abc" also causes the ContentStringFormat property to be aliased to AbcStringFormat.
The two most useful values for this property are "Content" and "Header".
(MSDN)
ContentSource
apparently sets more properties at once for convenience.
Practically, The declaration:
<ContentPresenter ContentSource="Header" />
Performs the following initialization.
<ContentPresenter Content="{TemplateBinding Header}"
ContentTemplate="{TemplateBinding HeaderTemplate}"
ContentTemplateSelector="{TemplateBinding HeaderTemplateSelector}"
ContentStringFormat="{TemplateBinding HeaderStringFormat}" />
It does this for each property separately only if the dependency property exists on the templated control.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With