プロパティ値の継承
WindowsフォームやVB 6のフォームではFontやBackColorといった一部のプロパティがアンビエントプロパティというものになっており、値を設定しない場合には親コントロールから値が取得されるようになっていました。
WPFでも、やはりFontSizeやBackgroundといった一部のプロパティが親から値を継承するようになっています。たとえば、WindowのFontSizeプロパティを72に設定した場合、その子のGridのそのまた子のButtonのFontSizeプロパティは72に設定されます。
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WindowsApplication1" Height="300" Width="300"
FontSize="72"
>
<Grid>
<Button Name="btn" Margin="50" Content="{Binding ElementName=btn, Path=FontSize}"/>
</Grid>
</Window>
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WindowsApplication1" Height="300" Width="300"
FontSize="72"
>
<Grid>
<Button Name="btn" Margin="50" Content="{Binding ElementName=btn, Path=FontSize}"/>
</Grid>
</Window>
プロパティ値が継承されるプロパティはDependencyプロパティでFrameworkPropertyMetadataOptionsがInheritsとなっているものです。Dependencyプロパティについては、また機会と時間があれば説明したいと思います。