wpf property inheritance
I want ask a question about that code its simple XAML code 开发者_开发知识库as show as below.
<Window x:Class="WpfApplication15.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" Background="Orange" FontStyle="Italic">
<StackPanel>
<Label>blo</Label>
<Button>hi</Button>
<Button>hi2</Button>
</StackPanel>
</Window>
So simply we can imagine, labels background orange but background color of button wont be orange will be as default, but all controls FontStyle will be italic, so question is that! why fontstyle of all control under root affected that but button's background doesn't??
I suppose that the ControlTemplate of the button sets the Background-brush explicitely in respect to windows ui-guidelines. Therefore property-inheritance is broken for the Control.BackgroundProperty
.
To prove it, maybe this tool will help.
This is the definition of the default button template , Microsoft_Windows_Themes:ButtonChrome is doing the trick
<ControlTemplate TargetType="{x:Type Button}">
<Microsoft_Windows_Themes:ButtonChrome x:Name="Chrome" SnapsToDevicePixels="true" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" RenderDefaulted="{TemplateBinding IsDefaulted}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" RecognizesAccessKey="True"/>
</Microsoft_Windows_Themes:ButtonChrome>
精彩评论