tags:

views:

42

answers:

2

Hello fox 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>

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 effected that but button's bacground doesnt?? thanks for reply

A: 

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.

HCL
so do i have to memorize which properties can be broken or not! i need solid answer logically
A: 

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>
Kishore Kumar
sorry but i dont get it! i still didnt get my answer.
the default button is made of Microsoft_Windows_Themes:ButtonChrome and there they are giving a staticresource for the background that's why button is not showing the background.
Kishore Kumar