WPF Triggering by ancestral property
Asked Answered
A

1

6

I would like to use a trigger, but need to select the ancestor's property, for example:

<Trigger Property="State" Value="Expanded">
   <Setter Property="Background" Value="Red" />
</Trigger>

Only that the State property need to be the property of an unknown ancestor by a known Type and if could not be found then trigger would never execute.

So my question is how can I find the ancestor to get the property to use in the trigger?

Hope I made myself clear. Thank you in advance.

Ader answered 10/4, 2013 at 12:43 Comment(0)
S
8
<DataTrigger Binding="{Binding State, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Whatever}}}" Value="Expanded">
Sn answered 10/4, 2013 at 16:53 Comment(1)
Worked perfectly. No need for FindAncestor since it is default. Thank you.Ader

© 2022 - 2024 — McMap. All rights reserved.