#136 – Dependency Property Value Sources: #3 – Parent Template

The third source in the list of sources for the base value of a dependency property is a parent template.  A property obtains its value from a parent template if the element for which the property is being set was created as part of a template and it doesn’t obtain its value through a trigger.

In the example below, the excitedLabel template has two child Label controls.  The first one has its Background property set in the template, so the source of the base value is the parent template.

        <ControlTemplate x:Key="excitedLabel" TargetType="Label">
            <StackPanel Orientation="Horizontal">
                <Label Name="theYee" Background="AliceBlue" Content="Yee!"/>
                <ContentPresenter />
                <Label Name="theHaw" Content="Haw!"/>
    <StackPanel Orientation="Vertical">
        <Label Content="Run" />
        <Label Content="Skip" Template="{StaticResource excitedLabel}"/>


About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

One Response to #136 – Dependency Property Value Sources: #3 – Parent Template

  1. Pingback: #133 – Where a Dependency Property Gets Its Value « 2,000 Things You Should Know About WPF

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: