GeorgeDuke
GeorgeDuke

Reputation: 151

WPF Custom ToolTip

I am using .Net 4.7.2 and WPF 4.5.1

I created a custom control which I use as ToolTip. The custom control works and I can apply it to a UI control, a TextBox for example.

Unfortunately, I don't find a way, to get rid of the typical frame of the common tooltip, which reminds me of a Button.

But have a look

ToolTip with a frame

I've tried to override the default style of tooltips, like shown in several examples here on stackoverflow and other sites as well.

Unfortunately, that doesn't solve my problem.

My xaml code looks like this:

<TextBox>
    <TextBox.ToolTip>
        <local:MyToolTip Text="{Binding MyToolTipText}" />
    </TextBox.ToolTip>
</TextBox>

How can I remove the button like border around the ToolTip?

Thanks in advance

Clarification:

I've tried two approaches:

first one:

<Style TargetType="{x:Type ToolTip}">

    <Setter Property="SnapsToDevicePixels"                        Value="True" />

    <Setter Property="Control.Template">
        <Setter.Value>
            <ControlTemplate>

                <Border VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Background="Black">

                    <!-- other content -->

                </Border>


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

</Style>

second one:

<Style TargetType="{x:Type MyToolTip}">

    <Setter Property="SnapsToDevicePixels"                       Value="True" />

    <Setter Property="Control.Template">
        <Setter.Value>
            <ControlTemplate>

                <local:MyToolTip />

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

</Style>

The Custom Control does NOT derive from ToolTip, but from Control

public class ToolTip : Control
{
    // ...
}

As I mentioned already, there is no problem with the code of the control, I'm struggling with a styling problem.

Upvotes: 1

Views: 2855

Answers (1)

Rekshino
Rekshino

Reputation: 7325

The border comes from ControlTemplate of ToolTip. Change the ControlTemplate and you will get rid of border:

<TextBox Text="text box text">
    <TextBox.Resources>
        <Style TargetType="ToolTip">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ToolTip">
                        <ContentPresenter />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </TextBox.Resources>
    <TextBox.ToolTip>
        <TextBlock Text="TEST" >
        </TextBlock>
    </TextBox.ToolTip>
</TextBox>

So it looks out without and with Style:
enter image description here

Upvotes: 1

Related Questions