Reputation: 416
I am using Hyperlink
in TextBlock
. The problem I am facing is when NavigateUri
is null, I don't want to set Hyperlink
or use default style, so that there is no difference between TextBlock
and Hyperlink
. How to do this?
The code that I am using is this:
<TextBlock TextWrapping="Wrap">
<Hyperlink NavigateUri="{Binding Path=Href}" RequestNavigate="Hyperlink_RequestNavigate">
<Run Text="{Binding Path=Body}"/>
</Hyperlink>
</TextBlock>
Sometimes Href
is null. That time I don't have to set NavigateUri
.
Upvotes: 0
Views: 473
Reputation: 4923
The solution I used is using DataTrigger to check Href value, if is equals to Null, set the related properties to imitate TextBlock's style
<Style TargetType="{x:Type Hyperlink}">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Href}" Value="{x:Null}">
<Setter Property="Foreground" Value="Black" />
<Setter Property="TextBlock.TextDecorations" Value="{x:Null}" />
<Setter Property="Cursor" Value="Arrow" />
</DataTrigger>
</Style.Triggers>
</Style>
Null value:
!Null Value:
Upvotes: 3