WPF hint disappears on mouse

I have a tooltip for an item that I want to stay open even when the user presses or holds the mouse button while over my item.

Is there any way to do this?

+7
wpf tooltip mouse
source share
2 answers

There is a StaysOpen tooltip property, but according to this book, you'd better use the Popup control (just make it look like a tip tool).

Here is a quote from the book:

It has no effect in practice. The purpose of this property is so that you can create a tooltip that remains open until the user clicks somewhere else. However, the ToolTipService.ShowDuration property overrides the StaysOpen property. As a result, tooltips always disappear after a custom amount of time (usually around 5 seconds) or when the user moves the mouse. If you want to create a popup that remains open indefinitely, the easiest approach is to use the Popup control.

+8
source share

The easiest way is to use Popup. Look at the sample code.

<!--Your ToolTip--> <Popup x:Name="InfoPopup" PlacementTarget="{Binding ElementName=yourElement}" AllowsTransparency="True" StaysOpen="False" Placement="Mouse" PopupAnimation="Fade"> <Border BorderBrush="White" BorderThickness="1" Background="#FFFFFFFF" > <Label Content="Your text here" /> </Border> </Popup> <!--Your element. Border, Button etc..--> <Border x:Name="yourElement" Background="#FFFFFF" MinWidth="20" Height="20"> <Border.Triggers> <EventTrigger RoutedEvent="Mouse.MouseDown"> <BeginStoryboard> <Storyboard> <BooleanAnimationUsingKeyFrames Duration="0:0:0:0" Storyboard.TargetProperty="IsOpen" Storyboard.TargetName="InfoPopup"> <DiscreteBooleanKeyFrame Value="True"></DiscreteBooleanKeyFrame> </BooleanAnimationUsingKeyFrames> </Storyboard> </BeginStoryboard> </EventTrigger> <EventTrigger RoutedEvent="Mouse.MouseUp"> <BeginStoryboard> <Storyboard> <BooleanAnimationUsingKeyFrames Duration="0:0:0:0" Storyboard.TargetProperty="IsOpen" Storyboard.TargetName="InfoPopup"> <DiscreteBooleanKeyFrame Value="False"></DiscreteBooleanKeyFrame> </BooleanAnimationUsingKeyFrames> </Storyboard> </BeginStoryboard> </EventTrigger> </Border.Triggers> </Border> 
+1
source share

All Articles