How can I style an element based on changes in child properties? I would accept a different approach, but the desired result is simply that the parent property is set a certain way as long as a a child property (IsPressed) is true.
If we are styling one named item with an in-line style we can simply identify our child using ElementName, but we can even be less specific and use Child.IsPressed:
<Border Name="parentBorder" Padding="20"> <Button Name="childButton" Content="Don't Push Me Bro"/> <Border.Style> <!--Now how can I do this from a static resource where I don't know the elementname?--> <Style TargetType="Border"> <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Child.IsPressed}" Value="True"> <Setter Property="Background" Value="Blue"/> </DataTrigger> </Style.Triggers> </Style> </Border.Style> </Border> But since I want to reuse the style and style several Borders I would like to move it to a resource, which is identical, except of course we are making a presumption that Child will always be a Button:
<Style x:Key="ButtonBorder" TargetType="{x:Type Border}"> <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Child.IsPressed}" Value="True"> <Setter Property="Background" Value="Blue"/> </DataTrigger> </Style.Triggers> </Style> What is the best approach, or what am I missing? I can see that when "Child" is used as an inline style, intellisense colors Child differently and I'm sure that means something. Is assuming things about the type of Child from resource-defined styles just no good?