How to Customize ToolTip Control: WPF

As in previous post, we have discussed about the tooltip control or tooltip property of the WPF controls. We can customize this tooltip according to our requirements. As in windows operating system, some controls use a rectangle in its tooltip service.

The following code will use a stack panel control in the tooltip of button. The stack panel have two textboxes and an image displayed in the screenshot shown below.
<Button Margin="5" Content="Submit" Width="200" Height="30">
<Button.ToolTip>
<StackPanel Width="180" Height="150">
<TextBlock Margin="2" Text="Introduction of Button" Background="Aqua" Foreground="Red"/>
<Image Margin="2" Source="wall.jpg" Height="100"></Image>
<TextBlock Margin="2" Text="For more help click F1" Background="BlueViolet" Foreground="Azure"/>
</StackPanel>
</Button.ToolTip>
</Button>
Run the project and a button will show, when we hover the mouse on it then the tooltip will display. Look out the following image:

How to Customize ToolTip control in WPF, XAML


Tooltip service have its open and close events to act on appearing and disappearing of the tooltip. It have some special properties to be used mostly by the programmer.

  • ShowDuration: to specify the duration till the tooltip will be shown. It is in millisecond.
  • ShowOnDisable: it enable or disable the tooltip when the control is disabled.
  • Placement: to place the tooltip on desired direction. It may be left, right, bottom, absolute and some more.
  • HasDropShadow: enable or disable the drop shadow effect of tooltip.

Some more properties are there, but can be used as per need.
How to Customize ToolTip Control: WPF How to Customize ToolTip Control: WPF Reviewed by Subhash Sharma on September 13, 2013 Rating: 5

No comments