Click here to Skip to main content
15,917,533 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to disable textbox's ToolTip on Mouse Over, Please help
Here is my Textbox Control Template

What I have tried:

<ControlTemplate x:Key="TextboxWithWatermark" TargetType="{x:Type TextBox}">
        <Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="True" Background="{TemplateBinding Background}">
            <Grid>
                <ScrollViewer x:Name="PART_ContentHost" Focusable="False" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
                <TextBlock Cursor="IBeam" VerticalAlignment="Top" x:Name="HintPresenter" FontFamily="{TemplateBinding FontFamily}" FontSize="{TemplateBinding FontSize}" FontWeight="{TemplateBinding FontWeight}" Margin="5,0,5,0" HorizontalAlignment="Left" Foreground="{TemplateBinding Foreground}" FontStyle="Italic" Opacity="0" Text="{TemplateBinding ToolTip}"/>
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Opacity" TargetName="border" Value="0.56"/>
            </Trigger>
            <Trigger Property="Text" Value="" >
                <Setter Property="Opacity" TargetName="HintPresenter" Value="0.5"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
Posted
Updated 30-Jul-17 1:38am
v3

1 solution

There is no tooltip set in the code shared. If you are seeing one, then it is set somewhere else - code that is not shared in the question. Check against the actual code in the Page or View or in the code-behind.

Update
Why not simply work with the ToolTipService and the IsEnabled property. Example:
C#
<TextBox Text="Is Enable Test" Width="100"
         ToolTipService.IsEnabled ="{Binding ElementName=EnabledState, Path=IsChecked}"
         ToolTipService.ToolTip="This is a tooltip for the textbox"/>
<CheckBox x:Name="EnabledState" Content="Show Tooltip" IsChecked="True" Margin="10 0" />
 
Share this answer
 
v2
Comments
Member 12680324 30-Jul-17 7:48am    
I want to hide tooltips when mouse is over textbox
<Window.Resources>
        <ControlTemplate x:Key="TextboxWithWatermark" TargetType="{x:Type TextBox}">
            <Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="True" Background="{TemplateBinding Background}">
                <Grid>
                    <ScrollViewer x:Name="PART_ContentHost" Focusable="False" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
                    <TextBlock Cursor="IBeam" VerticalAlignment="Top" x:Name="HintPresenter" FontFamily="{TemplateBinding FontFamily}" FontSize="{TemplateBinding FontSize}" FontWeight="{TemplateBinding FontWeight}" Margin="5,0,5,0" HorizontalAlignment="Left" Foreground="{TemplateBinding Foreground}" FontStyle="Italic" Opacity="0" Text="{TemplateBinding ToolTip}"/>
                </Grid>
            </Border>
            <ControlTemplate.Triggers>
                <Trigger Property="IsEnabled" Value="False">
                    <Setter Property="Opacity" TargetName="border" Value="0.56"/>
                </Trigger>
                <Trigger Property="Text" Value="" >
                    <Setter Property="Opacity" TargetName="HintPresenter" Value="0.5"/>
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
    </Window.Resources>
    <Grid x:Name="MainGrid">
        <StackPanel Margin="10" Width="150" HorizontalAlignment="Left">
            <Label Content="Information"/>
            <TextBox Template="{DynamicResource TextboxWithWatermark}" ToolTip="First name" Margin="1"/>
            <TextBox Template="{DynamicResource TextboxWithWatermark}" ToolTip="Last name" Margin="1"/>
            <TextBox Template="{DynamicResource TextboxWithWatermark}" ToolTip="Address" Margin="1"/>
            <TextBox Template="{DynamicResource TextboxWithWatermark}" ToolTip="E-mail address" Margin="1"/>
            <TextBox Template="{DynamicResource TextboxWithWatermark}" ToolTip="Tel" Margin="1"/>
            <Button Content="Send" HorizontalAlignment="Right"/>
        </StackPanel>
    </Grid>
Graeme_Grant 30-Jul-17 8:23am    
I'm not understanding why you would do that - sounds very odd.

But if you want to hide/show on Mouse, you have two choices:
1. Styles: use event triggers for MouseEnter & MouseLeave
2. ControlTemplate (as above) you use the VisualStateManager
Graeme_Grant 30-Jul-17 8:54am    
Had another thought for you. Check out the updated solution.
Member 12680324 30-Jul-17 12:47pm    
ToolTipService.IsEnabled is working, Thank you


Now the ToolTip become a textbox's watermark when textbox is string.empty without showing any tooltip on mouse over


<Trigger Property="IsMouseOver" Value="true">
<Setter Property="ToolTipService.IsEnabled" Value="False"/>


I'm not sure this's right how to use. But it still work

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900