In my custom control I want to programmaticaly enable or disable tooltip depending on options. Here is how my icon defined in template:
<Image x:Name="PART_IconImage" Stretch="None" VerticalAlignment="Top" HorizontalAlignment="Center" Source="{TemplateBinding Icon}"
ToolTipService.ToolTip="{TemplateBinding Caption}" />
I'm using this code to access ToolTip and to enable/disable it:
// Enable tooltip when caption not shown
if (this.IconImage != null)
{
var toolTip = ToolTipService.GetToolTip(this.IconImage) as ToolTip;
if (toolTip != null)
toolTip.IsEnabled = this.CaptionVisibility.HasValue
? (this.CaptionVisibility.Value == Visibility.Collapsed)
: (this.ParentToolbar.CaptionsVisibility == Visibility.Collapsed);
}
GetToolTip returns null. Any idea why?
P.S. I was following this advice here: How to programmatically access ToolTipService of a Silverlight FrameworkElement? But it doesn't work for me.