Why tooltip delay does not work as expected?

Aleksey Timoshchenko :

I have a ToolTip implementation for my Button

<Button Grid.Row="0"
                                    ToolTip="{x:Static res:Resources.tooltip_add_clip_s_for_processing}"
                                    x:Name="Btn_path_to_clip_folder"
                                    Click="Btn_path_to_clip_folder_Click"
                                    Content="{x:Static res:Resources.add_dots}"
                                    Cursor="Hand"
                                    Margin="4"
                                    HorizontalAlignment="Stretch"/>

But tooltip appears almost immediately after I point on it, so I need to add delay. I found such a solution

https://stackoverflow.com/a/1623298/5709159

So, I created such class under my utils dir

namespace My_proj.Utils
{
    public static class ToolTipServiceHelper
    {
        static ToolTipServiceHelper() => ToolTipService.InitialShowDelayProperty
                .OverrideMetadata(
            typeof(FrameworkElement),
            new FrameworkPropertyMetadata(ToolTipService.InitialShowDelayProperty.DefaultMetadata.DefaultValue,FrameworkPropertyMetadataOptions.Inherits));
    }
}

and then I include this in my UserControl

<UserControl x:Class="MMy_proj.UserControls.UCClipProcessing"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:converters="clr-namespace:My_proj.Converters"
             xmlns:res="clr-namespace:My_proj.Properties"
             xmlns:vm="clr-namespace:My_proj.Model.Binding;assembly=My_proj"
             Background="WhiteSmoke"
             mc:Ignorable="d" 
             ToolTipService.InitialShowDelay="2000"           <--- !!! This line
             d:DesignHeight="800" d:DesignWidth="1000">
...
</>

But anyway it doesn't work, still, when I point on the button I see a tooltip immediately

What am I doing wrong?

Sven Bardos :

I'm not sure how the solution from the other thread is supposed to work. It didn't change anything in my tests.

Only thing worked for me:

public MainWindow()
        {
            InitializeComponent();

            ToolTipService.InitialShowDelayProperty
                .OverrideMetadata(typeof(FrameworkElement),
                    new FrameworkPropertyMetadata(2000));
        }

Obvious drawback: Delay is not configured in XMAL, but in code behind.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=368463&siteId=1