I've made a style that makes TextBlock
look like a link:
<Style x:Key="linkStyle" TargetType="TextBlock">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="TextDecorations" Value="Underline" />
</Trigger>
</Style.Triggers>
<Setter Property="Cursor" Value="Hand" />
<Setter Property="Foreground" Value="Blue" />
<EventSetter Event="MouseLeftButtonDown" Handler="navigateLink" />
</Style>
How to apply it only when TextBlock.Text
starts with http:// ?
try this
<Style x:Key="linkStyleConditional" TargetType="{x:Type TextBlock}">
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsMouseOver}" Value="True"/>
<Condition Binding="{Binding Path=Text, Converter={StaticResource SomeConverter}}" Value="True"/>
</MultiDataTrigger.Conditions>
<Setter Property="Foreground" Value="Orange" />
</MultiDataTrigger>
</Style.Triggers>
</Style>
In SomeConverter write the logic if text start with http//: then return true else return false. i hope this will help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With