VisionTeknology
asked on
Content Presenter (WPF)
I am just looking through a sample piece of code
<TabControl.ItemTemplate>
<DataTemplate>
<ContentPresenter Content="{Binding DisplayName}" />
</DataTemplate>
</TabControl.ItemTemplate>
Why would they use a Content Presenter?
<TabControl.ItemTemplate>
<DataTemplate>
<ContentPresenter Content="{Binding DisplayName}" />
</DataTemplate>
</TabControl.ItemTemplate>
Why would they use a Content Presenter?
ASKER
The binding is a string, could you not use a <TextBlock>?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ContentPresenter is very handing when overriding templates.
For example, if you were overriding the template of a label, to put it in a grid or stackpanel or something, then the ContentPresenter will render all of the xaml markup in the original control.
In this case, you could possibly have a list where the DisplayName actually has xaml in it,
<Label><StackPanel><TextBl
For something like this, the only way to get it to actually render the xaml properly is using the content presenter. If you just bound to another element, you would get a text version of the markup.
Now, in this particular case, I would be very surprised if DisplayName had anything other than a string in it, in which case using ContentPresenter is definitely overkill, but might be just to accommodate future expansions.