#144 – Dependency Property Value Sources: #10 – Inheritance
December 3, 2010 3 Comments
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"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:m="clr-namespace:PersonLib;assembly=PersonLib"
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"/>
</StackPanel>
</StackPanel>
</Window>
Here’s what the window looks like:

Pingback: Tweets that mention #144 – Dependency Property Value Sources: #10 – Inheritance « 2,000 Things You Should Know About WPF -- Topsy.com
Pingback: #158 – When to Create a Custom Dependency Property « 2,000 Things You Should Know About WPF
Pingback: #133 – Where a Dependency Property Gets Its Value « 2,000 Things You Should Know About WPF