How to style WPF tooltip like a speech bubble?

24,283

Use this Code:

<Window x:Class="WpfApplication2.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing"
    x:Name="Window"
    Title="MainWindow"
    Width="640"
    Height="480">

<Window.Resources>

    <Style x:Key="{x:Type ToolTip}" TargetType="ToolTip">
        <Setter Property="OverridesDefaultStyle" Value="true" />
        <Setter Property="HasDropShadow" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ToolTip">
                    <ed:Callout Name="Border"
                                Width="{TemplateBinding Width}"
                                Height="{TemplateBinding Height}"
                                MinWidth="100"
                                MinHeight="30"
                                Margin="0,0,0,50"
                                AnchorPoint="0,1.5"
                                Background="{StaticResource LightBrush}"
                                BorderBrush="{StaticResource SolidBorderBrush}"
                                BorderThickness="1"
                                CalloutStyle="RoundedRectangle"
                                Fill="#FFF4F4F5"
                                FontSize="14.667"
                                Stroke="Black">
                        <ContentPresenter Margin="4"
                                          HorizontalAlignment="Left"
                                          VerticalAlignment="Top" />
                    </ed:Callout>

                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</Window.Resources>
<Grid>
    <Button ToolTip="Hello" />
</Grid>

this is the begining, now you have to play with it... enjoy!

enter image description here

Share:
24,283
Mohammad Zare
Author by

Mohammad Zare

A developer that loves clean and meaningful codes

Updated on July 09, 2022

Comments

  • Mohammad Zare
    Mohammad Zare almost 2 years

    I want to shape my WPF tooltip like the image below:

    enter image description here

    How do I achieve this?

  • Mohammad Zare
    Mohammad Zare almost 12 years
    thank you harry. i have another question: should i add an assembly for xmlns:ed="schemas.microsoft.com/expression/2010/drawing"?
  • Harry
    Harry almost 12 years
    Yes, add Microsoft.Expression.Drawing assembly.
  • SepehrM
    SepehrM almost 10 years
    This tool tip is shown below the control! How to show it above the button?
  • SepehrM
    SepehrM almost 10 years
    To show it below the control simply add: <Setter Property="Placement" Value="Top"/>
  • Cfun
    Cfun almost 4 years
    I am not sure why it is not working anymore even that the new namespace schemas.microsoft.com/expression/blend/2008 don't raise any error.