1

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.

sdds
  • 2,021
  • 2
  • 25
  • 33
  • +1 for finding an interesting problem. I've had a look into it and unfortunately, I couldn't find a fix for you. If you have no luck finding a solution here, it might be worth registering these details on [Microsoft Connect](https://connect.microsoft.com/). – Sheridan Aug 13 '14 at 08:04
  • 1
    When a control is not enabled, it isn't involved in hit-testing or focus and so won't be a source for any input events. To produce a tooltip the control needs to be hit-testable. – Mashton Aug 13 '14 at 13:32

2 Answers2

4

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.

  • This answers my original question. However, this won't work if the IsEnabled property is databound. I posted a more specific question with a detailed answer [here](http://stackoverflow.com/questions/25403064/wpf-how-to-display-a-tooltip-on-a-hyperlink-only-when-the-hyperlink-is-disable). – sdds Aug 20 '14 at 11:28
  • This works in my scenario where a control is nested inside a disabled parent control. – JGeerWM Feb 04 '16 at 21:25
1

Move Tooltip to textblock like this

<TextBlock TextAlignment="Center" Margin="5" ToolTip="ToolTip">
    <Hyperlink IsEnabled="False" ToolTipService.ShowOnDisabled="True">
        <TextBlock Text="Text"/>
    </Hyperlink>
</TextBlock>
ebattulga
  • 10,774
  • 20
  • 78
  • 116
  • But that will make the tooltip show on the whole TextBlock area, and not just on the hyperlink's text. I mentioned that I want to avoid that. – sdds Aug 13 '14 at 07:25