Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clickable hyperlink on tooltip or popup in WPF

Tags:

c#

wpf

tooltip

xaml

I need to show a hyperlink on a tooltip. The hyperlink should be clickable. My XAML so far is:

<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:

the output

But it is not clickable and hides immediately. I need the link to be clickable.

like image 694
Kathir Subramaniam Avatar asked Feb 23 '16 16:02

Kathir Subramaniam


1 Answers

You will have to roll your own "Tooltip" using the Popup. Tooltips are not designed to be interactive as you are requesting but popup windows are and offer more control over the displaying functionality.

You can then control the popup opening through similar events that the tooltip service provides (mouse over, mouse leave etc.)

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

And the code behind is just using mover over on button and leave from popup. You would have to derive your own showing methodology that meets the users requirements.

private void bttnTarget_MouseLeave(object sender, MouseEventArgs e)
{
    tooltip.IsOpen = false;
}
private void bttnTarget_MouseEnter(object sender, MouseEventArgs e)
{
    tooltip.IsOpen = true;
}
like image 55
N_tro_P Avatar answered Nov 02 '22 17:11

N_tro_P