WPF - 带有嵌入式TextBlock元素的已禁用超链接上的工具提示 [英] WPF - Tooltip on a disabled hyperlink with an embedded TextBlock element

查看:173
本文介绍了WPF - 带有嵌入式TextBlock元素的已禁用超链接上的工具提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的WPF应用中将工具提示放在禁用的超链接上。超链接具有用于Text参数绑定的嵌入TextBlock元素。但是,由于某些原因,工具提示不适用于具有嵌入式TextBlock元素的禁用超链接。以下是一个示例:

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>

此XAML描述了三个超链接。

This XAML describes three hyperlinks.


  • 第一个超链接已禁用,但没有嵌入的TextBlock元素。工具提示显示正常。

  • 第二个超链接具有嵌入的TextBlock元素,但已启用。同样,工具提示显示正常。

  • 第三个超链接被禁用并具有嵌入式TextBlock元素,这是我需要的,但工具提示未显示

  • 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.

如何在带有嵌入式TextBlock元素的已禁用超链接上显示工具提示?我不想将工具提示添加到父TextBlock,因为我希望工具提示只出现在超链接文本上,而不是整个TextBlock区域。

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.

谢谢。

推荐答案

我知道这听起来很奇怪,但这似乎有效:

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>

即,您必须禁用父TextBlock。

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

这篇关于WPF - 带有嵌入式TextBlock元素的已禁用超链接上的工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆