2
votes

Consider the following simple code.

When I hover the mouse on any item, it waits for 1 second and then it shows the ToolTip as expected. However, if i move the mouse to another item without getting out of the list, the tooltip simply updates to the new item name without retriggering a show delay. Is this normal behavior?

I need for the tooltip to disappear when moving the mouse across the list whenever it enters a new item and retrigger a show delay. Any suggestions?

MainWindow.xaml

<Window x:Class="WpfApplication.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:lcl="clr-namespace:WpfApplication"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <ListBox HorizontalContentAlignment="Stretch" ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=Window}, Path=Items}">
            <ListBox.ItemTemplate>
                <DataTemplate DataType="lcl:Item">
                    <TextBlock 
                        Text="{Binding Name}"
                        HorizontalAlignment="Stretch"
                        ToolTipService.InitialShowDelay="1000"
                        ToolTipService.BetweenShowDelay="1000"
                        ToolTipService.HasDropShadow="True"
                        ToolTipService.HorizontalOffset="5"
                        ToolTipService.VerticalOffset="5">
                        <TextBlock.ToolTip>
                            <TextBlock Text="{Binding Name}" />
                        </TextBlock.ToolTip>
                    </TextBlock>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
</Window>

MainWindow.xaml.cs

namespace WpfApplication
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            _Items.Add(new Item() { Name = "First" });
            _Items.Add(new Item() { Name = "Second" });
            _Items.Add(new Item() { Name = "Third" });
        }

        public Collection<Item> _Items = new Collection<Item>();
        public Collection<Item> Items
        {
            get { return _Items; }
        }
    }

    public class Item
    {
        public string Name
        {
            get;
            set;
        }
    }
}
3

3 Answers

2
votes

I am afraid that you misunderstood how the BetweenShowDelay property works. As you can read here:

In the [...] example, the InitialShowDelay property is set to one second (1000 milliseconds) and the BetweenShowDelay is set to two seconds (2000 milliseconds) for the tooltips of both Ellipse controls. If you display the tooltip for one of the ellipses and then move the mouse pointer to another ellipse within two seconds and pause on it, the tooltip of the second ellipse displays immediately.

Take a look to the example in the link above for more details.

So - as you can see - the one that you describe is the normal behavior.

0
votes

This seems to work as expected for me, i.e. don't set the ToolTipService.BetweenShowDelay property:

<TextBlock 
    Text="{Binding Name}"
    HorizontalAlignment="Stretch"
    ToolTipService.InitialShowDelay="5000"
    ToolTipService.HasDropShadow="True"
    ToolTipService.HorizontalOffset="5"
    ToolTipService.VerticalOffset="5">
    <TextBlock.ToolTip>
        <TextBlock Text="{Binding Name}" />
    </TextBlock.ToolTip>
</TextBlock>
0
votes

I am also seeing the behavior that the OP was questioning. The entire reason I added the property ToolTipService.BetweenShowDelay was because I thought it would fix the problem, but as said here we are misunderstanding what it does.

Perhaps this is a bug in WPF, because even without setting BetweenShowDelay, the moment the mouse moves to another element, the tooltip just changes instead of the previous tooltip closing and then waiting to open the new one.

I am wondering if it has to do with using a Data Template?