Proton
Proton

Reputation: 236

Always show WPF TextBox Tooltip

Is it possible to display tooltip constantly, not depending on whether the control is focused ot not, but depending only on the value of the bind property.

<TextBox Name="projectTextBox" 
         ToolTipService.Placement="Bottom" ToolTipService.ShowDuration="12000" 
         MinWidth="150" Text="{Binding ProjectName}" IsEnabled="{Binding IsEnabled}">
    <TextBox.ToolTip>
        <ToolTip Placement="Bottom" 
                 StaysOpen="True" Content="TEXT" 
                 Visibility="{Binding IsNotFound, Converter={StaticResource booleanToVisibilityCollapsedConverter}}" 
                 IsOpen="True">
        </ToolTip>
    </TextBox.ToolTip>
</TextBox>

Upvotes: 1

Views: 9547

Answers (4)

I.Step
I.Step

Reputation: 779

You can consider using Popup instead. Or if you are using material design for WPF, you can consider using PopupBox. I know I late for the party this time.

Upvotes: 0

blindmeis
blindmeis

Reputation: 22445

you should use an adorner for the behavior you are looking for. you can use a datatrigger or what you want to show the adorner as long as you want. btw with an adorner you did not have the problems popups have, while moving the mainwindow.

Upvotes: 2

Andrei Pana
Andrei Pana

Reputation: 4502

Basically, you cannot force the tooltip to be shown constantly, because Windows is the one who decides when the tooltip hides (usually on MouseLeave or after some amount of time) to keep the look and feel of the applications consistent (The tooltip control is made to act this way).

If you want to display some helpful information to the user in a way that differs from the standard Windows tooltip way, you should consider using something else than a ToolTip, maybe a Popup or something similar with the FormNotification control from this article.

Upvotes: 0

Rachel
Rachel

Reputation: 132558

Why not set the tooltip based on a trigger?

<TextBox Name="projectTextBox" ToolTipService.Placement="Bottom" ToolTipService.ShowDuration="12000" MinWidth="150" Text="{Binding ProjectName}" IsEnabled="{Binding IsEnabled}">
    <TextBox.Style>
        <Style TargetType="{x:Type TextBox}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsNotFound}" Value="False">
                    <Setter Property="ToolTip">
                        <Setter.Value>
                            <ToolTip Placement="Bottom" StaysOpen="True" Content="TEXT"  IsOpen="True" />
                        </Setter.Value>
                    </Setter>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </TextBox.Style>
</TextBox>

Upvotes: 1

Related Questions