Reputation: 996
I have a Button
which uses a ControlTemplate
, this template contains multiple MultiDataTriggers
which change the appearance depending on User Interaction and View Model properties. Therefore, I cannot use traditional Triggers
.
The Triggers in question (examples)
XAML:
<DataTrigger Binding="{Binding IsPressed, RelativeSource={RelativeSource TemplatedParent}}" Value="True">
<Setter TargetName="Text" Property="Content" Value="IsPressed"/>
</DataTrigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="Text" Property="Content" Value="IsPressed"/>
</Trigger>
The DataTrigger fails, yet the normal Trigger does not. Why?
Note:
I have tried multiple approaches to binding, such as AncestorType
, but have had no success. These triggers have also been tested independently with the same problem persisting.
Upvotes: 0
Views: 904
Reputation: 169150
Try {RelativeSource Self}
:
<DataTrigger Binding="{Binding IsPressed, RelativeSource={RelativeSource Self}}" Value="True">
<Setter TargetName="Text" Property="Content" Value="IsPressed"/>
</DataTrigger>
Upvotes: 2