The code at the bottom makes the DockPanel Visibility=Collapsed whenever the TextBlock has an empty string value, which is what I want. However, I happened on this by accident and am wondering why setting the DockPanel.Visibility attached property in the TextBlock affects the DockPanel.
I know that DockPanel.Dock is an attached property you can directly set in an element e.g.
<TextBlock DockPanel.Dock="Top"/>
..but you cannot set
<TextBlock DockPanel.Visibility="Collapsed"/>
..in the same way.
So how does DockPanel know to query child elements for DockPanel.Visibility, or do parent elements always query children for all attached properties and use these whenever the value is not set locally? I was under the impression only certain attached properties were used in this way (e.g. DockPanel.Dock).
Also, what other ways are there to acheive the same result (e..g using triggers set within a DockPanel style - problem there seems to be errorTextBlock name is not in scope)
<DockPanel x:Key="errorDisplay" LastChildFill="False">
<Border Background="Red" DockPanel.Dock="Top" BorderBrush="Black" BorderThickness="1">
<TextBlock Padding="4" x:Name="errorTextBlock">
<TextBlock.Style>
<Style>
<Style.Triggers>
<Trigger Property="TextBlock.Text" Value="">
<Setter Property="DockPanel.Visibility" Value="Collapsed"/>
</Trigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</Border>
</DockPanel>