views:

35

answers:

2
<Window x:Class="tests.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="Red" Foreground="Cyan">
    <StackPanel VerticalAlignment="Center">
        <Button>123</Button>
        <TextBlock>123</TextBlock>
        <TextBox>123</TextBox>
    </StackPanel>
</Window>

In the above code, only the TextBlock will "inherit" both the foreground and background colors. Shouldn't the Button and TextBox have those colors too? Why don't they have it? alt text

A: 
<Button background="{Binding ElementName=stackPanel1,Path=Background}" .../>
GLeBaTi
+1  A: 

This is because Button specially opted out of Background value inheritance, in order to have consistent look. See en.csharp-online.net/WPF_Concepts—Property_Value_Inheritance for more details.

Vlad