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;
}
}
}