#864 – Changing the Look of a ToolTip with a Control Template

You can change the content of a ToolTip if you want it to display more than simple text.  If you want to go further and change the look of the ToolTip more completely, you can use a control template.  This lets you display the tooltip’s content in something other than the default bordered popup.

The example below displays a ToolTip with a custom border and background.

        <Button Content="Caesar"
                Margin="5" Padding="10,5"
                HorizontalAlignment="Center">
            <Button.ToolTip>
                <ToolTip Content="Click to learn more about Julius Caesar (100 BC - 44 BC)"
                         OverridesDefaultStyle="True"
                         HasDropShadow="True">
                    <ToolTip.Template>
                        <ControlTemplate TargetType="ToolTip">
                            <Border BorderBrush="Blue" BorderThickness="1"
                                    Background="AliceBlue"
                                    CornerRadius="5">
                                <StackPanel Orientation="Horizontal">
                                    <Image Source="Caesar.jpg" Height="100"/>
                                    <TextBlock Text="{TemplateBinding Content}"
                                               Margin="10"
                                               Width="150" TextWrapping="Wrap"/>
                                </StackPanel>
                            </Border>
                        </ControlTemplate>
                    </ToolTip.Template>
                </ToolTip>
            </Button.ToolTip>
        </Button>

864-001

Advertisement

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

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 )

Facebook photo

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

Connecting to %s

%d bloggers like this: