Why only some children will have their properties defined by their parents

<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 TextBlock will β€œinherit” the foreground and background colors. Shouldn't these buttons have buttons and TextBox? Why don't they do it? alt text http://img707.imageshack.us/img707/8014/5uslgmbzkbyurgwuwgqtzv2.png

+4
source share
2 answers

This is because Button specifically rejected the inheritance of Background values ​​in order to have a consistent look. See en.csharp-online.net/WPF_Concepts-Property_Value_Inheritance for more details.

+1
source
 <Button background="{Binding ElementName=stackPanel1,Path=Background}" .../> 
-1
source

Source: https://habr.com/ru/post/1301946/


All Articles