WPF - Tooltip on a disabled hyperlink with an embe

2019-07-29 09:05发布

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.

2条回答
Anthone
2楼-- · 2019-07-29 09:38

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.

查看更多
贪生不怕死
3楼-- · 2019-07-29 09:39

Move Tooltip to textblock like this

<TextBlock TextAlignment="Center" Margin="5" ToolTip="ToolTip">
    <Hyperlink IsEnabled="False" ToolTipService.ShowOnDisabled="True">
        <TextBlock Text="Text"/>
    </Hyperlink>
</TextBlock>
查看更多
登录 后发表回答