Whats the difference between ContentControl.Template and ContentControl.ContentTemplate
Asked Answered
S

1

39

What's the difference between ContentControl.Template and ContentControl.ContentTemplate? And when do I use which?

For example I could write in a xaml file for WPF:

<ContentControl>
    <ContentControl.Template>
        <ControlTemplate>
            <Label Content="This is from the Template"/>
        </ControlTemplate>
    </ContentControl.Template>
</ContentControl>

Notice the ContentControl.Template Tag

or I could write this:

<ContentControl>
    <ContentControl.ContentTemplate>
        <DataTemplate>
            <Label Content="This is From the ContentTemplate"/>
        </DataTemplate>
    </ContentControl.ContentTemplate>
</ContentControl>

Notice the ContentControl.ContentTemplate Tag

The output looks the same and in the first case I use a ControlTemplate and in the other a DataTemplate. However, how should I deceide if I have to use .Template or .ContentTemplate? And what implications does this have (e. g. on DataBinding, Property Inheritance, ...).

Selfish answered 27/9, 2011 at 10:28 Comment(0)
V
29

Template property defines the appearence of a Control itself and ContentTemplate defines the template of the Content area of a Control. Interesting point from MSDN:

If a Control does not have a ControlTemplate, the Control will not appear in your application.

This becomes more clear when we take a look at the data types of both properties:

Vair answered 27/9, 2011 at 10:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.