Flexible hyperlink to a tooltip or popup in WPF

I need to show a tooltip hyperlink. The hyperlink must be interactive. So far my 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>

Output:

exit

But it is not clickable and hides immediately. I need a link for clickability.

+5
source share
1 answer

You will need to throw your own "tip" using the popup. Tooltips are not designed to work interactively as you request, but tooltips provide more control over the display.

, ( , ..)

<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;
}
+6

All Articles