Search code examples
c#wpfxamlhyperlinktooltip

WPF - Tooltip on a disabled hyperlink with an embedded TextBlock element


I'm trying to put tooltips on disabled hyperlinks in my WPF app. The hyperlinks have embedded TextBlock elements for Text parameter binding. However, for some reason tooltips don't work on disabled hyperlinks with an embedded TextBlock element. Here is an example:

<Grid>
    <StackPanel>
        <TextBlock TextAlignment="Center" Margin="5">
            <Hyperlink IsEnabled="False" ToolTip="ToolTip" ToolTipService.ShowOnDisabled="True">Text</Hyperlink>
        </TextBlock>
        <TextBlock TextAlignment="Center" Margin="5">
            <Hyperlink IsEnabled="True" ToolTip="ToolTip" ToolTipService.ShowOnDisabled="True">
                <TextBlock Text="Text"/>
            </Hyperlink>
        </TextBlock>
        <TextBlock TextAlignment="Center" Margin="5">
            <Hyperlink IsEnabled="False" ToolTip="ToolTip" ToolTipService.ShowOnDisabled="True">
                <TextBlock Text="Text"/>
            </Hyperlink>
        </TextBlock>
    </StackPanel>
</Grid>

This XAML describes three hyperlinks.

  • The first hyperlink is disabled, but has no embedded TextBlock element. The tooltip shows up fine.
  • The second hyperlink has an embedded TextBlock element, but is enabled. Again, the tooltip shows up fine.
  • The third hyperlink is disabled and has an embedded TextBlock element, which is what I need, but the tooltip is not shown.

What can I do to show tooltips on disabled hyperlinks with embedded TextBlock elements? I don't want to add the tooltip to the parent TextBlock, because I want the tooltip to only appear on the hyperlink text, and not the whole TextBlock area.

Thanks.


Solution

  • I know it sounds strange but this seems to work:

    <TextBlock Text="Hello there" IsEnabled="False">
        <Hyperlink ToolTip="ToolTip" ToolTipService.ShowOnDisabled="True">
            <TextBlock Text="Text" />
        </Hyperlink>
    </TextBlock>
    

    i.e., you have to disable the parent TextBlock.