【发布时间】:2011-12-27 15:40:34
【问题描述】:
在我的自定义控件中,我想根据选项以编程方式启用或禁用工具提示。这是我在模板中定义的图标的方式:
<Image x:Name="PART_IconImage" Stretch="None" VerticalAlignment="Top" HorizontalAlignment="Center" Source="{TemplateBinding Icon}"
ToolTipService.ToolTip="{TemplateBinding Caption}" />
我正在使用此代码访问工具提示并启用/禁用它:
// 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 返回 null。知道为什么吗?
附:我在这里遵循这个建议:How to programmatically access ToolTipService of a Silverlight FrameworkElement? 但这对我不起作用。
【问题讨论】:
标签: c# silverlight xaml