12 April 2011

WPF / Silverlight - Custom tooltip

Giving a control a customized tooltip in WPF or Silverlight is quite easy:
<Image Source="Help.png" Margin="4 2" Cursor="Hand" Stretch="None">
  <Image.ToolTip>
    <Border CornerRadius="4" Padding="2">
      <StackPanel Orientation="Vertical">
        <TextBlock x:Name="txtTitle" Margin="1" FontWeight="Bold" />
        <TextBlock x:Name="txtText" Margin="1" />
      </StackPanel>
    </Border>
  </Image.ToolTip>
</Image>

Moreover, by adding
ToolTipService.ShowDuration="60000"
to the control owning the tooltip, the tooltip will be displayed a whole minute instead of the default 5 seconds.

No comments:

Post a Comment