Thursday, February 7, 2013

WPF Tooltip

Adding a tooltip to a control in WPF is pretty simple. Here is the basic syntax.
<Button Content="Button" ToolTip="This is a tooltip"/> 


image


There are various properties that can be adjusted to tweak the behavior of the tooltip. This is done via the TooltipService attached property.


<Button Content="Button" ToolTip="This is a tooltip"
                ToolTipService.HasDropShadow="False">
            
</Button>


The properties that can be tweaked on the TooltipService are:

BetweenShowDelay This value specifies how much time (in milliseconds) the user has to move from the control that is displaying the tooltip to another one without having to wait for it’s InitialShowDelay. Essentially, if I set this value to X, once I see the tooltip on my control, I have X milliseconds to hover over another control that has a tooltip and that other tooltip will show up immediately.
 
HasDropShadow Specifies if the tooltip has a dropshadow.
 
HorizontalOffset Offset from the left of the area that is specifies for the tooltip.
 
InitialShowDelay How long it takes for the tooltip to open (in milliseconds).
 
IsEnabled Determines whether the tooltip gets displayed.
 
IsOpen Gets whether the tooltip is open.
 
Placement Sets the orientation of the tooltip when it opens
 
PlacementRectangle Gets or sets the rectangle area in which the tooltip is displayed
 
ShowDuration Specifies the amount of time the tooltip is displayed
 
ShowOnDisabled Specifies if the tooltip is displayed when the parent object is disabled
 
ToolTip Gets or sets the content of the tooltip
 

VerticalOffset
Offset from the top of the area that is specifies for the tooltip.



You can any visual element as the content of a tooltip by defining in a nested element rather than an attribute.


        <Button Content="Button">            
            <ToolTipService.ToolTip>
                <Rectangle Fill="Red" Height="20" Width="20"/>
            </ToolTipService.ToolTip>
        </Button>



image


Happy Tooltiping!


No comments:

Post a Comment