I am watching an online video tutorial about DataTemplates
The demo code is the follows
<StackPanel.Resources>
<ControlTemplate x:Key="MyButton">
<Grid>
<Ellipse Fill="{TemplateBinding Background}" />
<ContentControl Content="{TemplateBinding ContentControl.Content}" /><!--why this-->
</Grid>
</ControlTemplate>
</StackPanel.Resources>
<Button Content="Click me" Background="Green" Width="100" Height="50" Template="{StaticResource MyButton}" />
</StackPanel>
The bit where I'm lost is
<ContentControl Content="{TemplateBinding ContentControl.Content}" />
Why is it ControlControl.Content
and not just Content
. If we review the line of code before this it shows Ellipse Fill="{TemplateBinding Background}"
and not <Ellipse Fill="{TemplateBinding Ellipse.Background}" />
Why do we state ContentControl
? Is it because the property Content
of the Button
is actually an object of type ContentControl
where as Background
is just a string property of Button
?