#144 – Dependency Property Value Sources: #10 – Inheritance

The tenth source in the list of sources for the base value of a dependency property is inheritance.  A property can get its base value through inheritance if an element higher up in the logical tree sets the property and the property is not overwritten due to a higher precedence rule.

This means that when you set a property value in XAML or in code, that value often “trickles down” the element tree and is applied to other elements that have a property of the same name.

Here’s an example. The value of FontStyle for several controls is inherited from the top-level Window element.

<Window x:Class="WpfApplication1.MainWindow"
        Title="MainWindow" Height="350" Width="525" FontStyle="Italic">
    <StackPanel Orientation="Vertical">
        <Button Content="Run" Height="23" Width="75" />
        <Button Content="Skip" Height="23" Width="75" />
        <StackPanel Orientation="Horizontal">
            <Label Content="Inside 2nd StackPanel"/>
            <Label Content="I do my own FontStyle" FontStyle="Normal"/>

Here’s what the window looks like:


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

4 Responses to #144 – Dependency Property Value Sources: #10 – Inheritance

  1. Pingback: Tweets that mention #144 – Dependency Property Value Sources: #10 – Inheritance « 2,000 Things You Should Know About WPF -- Topsy.com

  2. Pingback: #158 – When to Create a Custom Dependency Property « 2,000 Things You Should Know About WPF

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

  4. Pingback: #1,040 – An Example of Dependency Property Inheritance | 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 )

Facebook photo

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

Connecting to %s

%d bloggers like this: