In this case you can use the DataTrigger
:
Represents a trigger that applies property values or performs actions when the bound data meets a specified condition.
Example:
<DataTemplate>
<TextBlock Name="MyTextBlock" Tag="True">
<Hyperlink Name="MyHyperlink" Click="Hyperlink_Click">
<TextBlock Text="TestText" />
</Hyperlink>
</TextBlock>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Path=Tag, ElementName=MyTextBlock}" Value="True">
<Setter TargetName="MyHyperlink" Property="IsEnabled" Value="True" />
</DataTrigger>
<DataTrigger Binding="{Binding Path=Tag, ElementName=MyTextBlock}" Value="False">
<Setter TargetName="MyHyperlink" Property="IsEnabled" Value="False" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
If Tag
of TextBlock will be True, then Hyperlink
is enabled, otherwise it will be disabled.
Also, you can Binding the property in DataTrigger
. Add some property, for example HyperlinkIsEnabled
to your Data, and in the DataTrigger write this:
<DataTrigger Binding="{Binding Path=HyperlinkIsEnabled}" Value="False">
<Setter TargetName="MyHyperlink" Property="IsEnabled" Value="False" />
</DataTrigger>
To successfully updated your properties, your Data
class must implement the INotifyPropertyChanged
interface.