#858 – How to Set Properties for a Tooltip

There are basically three different ways to specify tooltips.  The first is to just set the Tooltip property on the control where the tooltip should appear.  You set the property to the text that you want to see in the tooltip.

        <Button Content="Read a Book"
                Padding="10,5" HorizontalAlignment="Center"
                ToolTip="You might start with Charles Dickens"/>

858-001
If you want to create a more complex tooltip, you can use the property element syntax.

        <Button Content="Read a Book"
                Padding="10,5" HorizontalAlignment="Center">
            <Button.ToolTip>
                <StackPanel>
                    <TextBlock Text="Reading Suggestion" FontWeight="Bold"/>
                    <TextBlock Text="Charles Dickens" Margin="5"/>
                </StackPanel>
            </Button.ToolTip>
        </Button>

858-002
Finally, if you want to specify property values for the ToolTip, you can use a ToolTip element.

        <Button Content="Read a Book"
                    Padding="10,5" HorizontalAlignment="Center">
            <Button.ToolTip>
                <ToolTip Foreground="Blue">
                    <StackPanel>
                        <TextBlock Text="Reading Suggestion" FontWeight="Bold"/>
                        <TextBlock Text="Charles Dickens" Margin="5"/>
                    </StackPanel>
                </ToolTip>
            </Button.ToolTip>
        </Button>

858-003

Advertisement

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

2 Responses to #858 – How to Set Properties for a Tooltip

  1. Pingback: Dew Drop – July 8, 2013 (#1,580) | Alvin Ashcraft's Morning Dew

  2. Pingback: #859 – Changing the Amount of Time That a ToolTip Is Shown For | 2,000 Things You Should Know About WPF

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: