WPF中的工具提示或弹出窗口中的可点击超链接

9

我需要在工具提示中显示一个超链接。这个链接应该是可点击的。到目前为止,我的XAML代码如下:

<Button Content="Click..!!"
        Height="23"
        HorizontalAlignment="Left"
        Margin="191,108,0,0"
        Name="button1"
        VerticalAlignment="Top"
        Width="75" >
    <Button.ToolTip>
        <ToolTip StaysOpen="True"
                 ToolTipService.BetweenShowDelay="5000"
                 ToolTipService.ShowDuration="5000"
                 ToolTipService.InitialShowDelay="5000">
            <Hyperlink NavigateUri="http://stackoverflow.com/questions/">http://stackoverflow.com/questions/</Hyperlink>
        </ToolTip>
    </Button.ToolTip>
</Button>

输出:

输出结果

但是链接不可点击且立即隐藏。我需要使链接可点击。

1个回答

10

您将需要使用Popup自己制作“提示”,因为提示不像您要求的那样设计成交互式的,但弹出窗口是可以的,并且提供更多对显示功能的控制。

然后,您可以通过类似于提示服务提供的事件(鼠标悬停,鼠标离开等)来控制弹出窗口的打开。

<Button x:Name="bttnTarget" MouseEnter="bttnTarget_MouseEnter" Content="Click..!!" Height="23" HorizontalAlignment="Left" Margin="191,108,0,0" VerticalAlignment="Top" Width="75" />
<Popup x:Name="tooltip" PlacementTarget="{Binding ElementName=bttnTarget}" MouseLeave="bttnTarget_MouseLeave" Placement="Bottom">
   <StackPanel>
      <TextBlock>
         <Hyperlink NavigateUri="http://stackoverflow.com/questions/">http://stackoverflow.com/questions/</Hyperlink>
      </TextBlock>
   </StackPanel>
</Popup>

而在幕后,代码仅仅是在按钮上使用了鼠标悬停,并离开弹出框。您需要推导出符合用户要求的自己的展示方法。

private void bttnTarget_MouseLeave(object sender, MouseEventArgs e)
{
    tooltip.IsOpen = false;
}
private void bttnTarget_MouseEnter(object sender, MouseEventArgs e)
{
    tooltip.IsOpen = true;
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接