(0 votes)

Tip: How to add a tooltip to a control?

0 comments   /   posted by Martin Mihaylov on Sep 11, 2008

If you want to add a tooltip to a control you must first check if it allows the ToolTipService namespace. If yes, you can add the tooltip the following way:

Xaml

<Button x:Name="MyButton" Content="Hello!" Width="50" Height="30">
    <ToolTipService.ToolTip>
        <TextBlock x:Name="ToolTip" Text="Click me!"></TextBlock>
    </ToolTipService.ToolTip>
</Button>

C#

ToolTipService.SetToolTip( MyButton, new TextBlock() { Text = "Click me!" } );

You can also use another control instead of TextBlock, for example Image control or Rectangle control.

That's it!
 

Filed under: Controls and UI


Comments

Comments RSS RSS
No comments

Add Comment