An interesting question..
Lets say you have a list view like this:
<ListView>
<ListView.Resources>
<Style TargetType="ListViewItem">
<Setter Property="ToolTip" Value="{Binding Content, RelativeSource={RelativeSource Mode=Self}}" />
</Style>
</ListView.Resources>
<ListViewItem>1</ListViewItem>
<ListViewItem>2</ListViewItem>
<ListViewItem>3</ListViewItem>
</ListView>
You can retrieve it using MouseMoveEvent: (in MainWindow.xaml.cs)
AddHandler(ListViewItem.MouseMoveEvent, (RoutedEventHandler)((o, e) =>
{
if (e.Source is ListViewItem)
{
string tooltip = (e.Source as ListViewItem).ToolTip as string;
if (tooltip != null)
Title = tooltip;
}
Debug.WriteLine(e.Source);
}));
If you want to hide the tooltip, you have to define another attached property, e.g.
public static readonly DependencyProperty ToolTipProperty =
DependencyProperty.RegisterAttached("ToolTip", typeof(string), typeof(MainWindow),
new PropertyMetadata(""));
public static void SetToolTip(DependencyObject obj, string value)
{
obj.SetValue(ToolTipProperty, value);
}
public static string GetToolTip(DependencyObject obj)
{
return (string)obj.GetValue(ToolTipProperty);
}
Regards
Joseph Leung