Silverlight 如何自定义ToolTipService.ToolTip的模板?
Silverlight为基本应用程序提供Silverlight 如何自定义ToolTipService.ToolTip的模板?,silverlight,silverlight-3.0,Silverlight,Silverlight 3.0,Silverlight为基本应用程序提供ToolTipService.ToolTip 但是,我想通过如下操作自定义工具提示的模板: <TextBlock Text="Hello" > <ToolTipService.ToolTip> <TextBlock Text="I can help you." /> <!--replace this with my template--> </ToolTipService.Tool
ToolTipService.ToolTip
但是,我想通过如下操作自定义工具提示的模板
:
<TextBlock Text="Hello" >
<ToolTipService.ToolTip>
<TextBlock Text="I can help you." /> <!--replace this with my template-->
</ToolTipService.ToolTip>
</TextBlock>
您将无法以您想要的方式使用Style属性。
ToolTipService.ToolTip
属性是一个附加属性。不能使用样式资源为附着的特性指定值
但是,您可以使用样式资源设置工具提示
元素的样式。因此,您的TextBlock
可能如下所示:-
<TextBlock Text="{Binding SomeProperty}">
<ToolTipService.ToolTip>
<ToolTip Style="{StaticResource TipHelp}" />
</ToolTipService.ToolTip>
</TextBlock>
现在,在容器资源中,您可以有如下样式:-
<Style x:Key="TipHelp" TargetType="ToolTip">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<TextBlock Text="{Binding SomeOtherProperty}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
现在,您可以根据所需的工具提示外观自定义
控制模板的内容,并将其与适当的绑定对象连接起来。有人遇到了同样的问题,并在CodePlex中创建了一个相当不错的项目
有了它,您甚至可以绑定工具提示
文本(这对我来说是一个限制,因为我通过绑定使用本地化)
以下是链接:
效果非常好。我知道这是一个迟来的评论,但您是否可以更新您的答案,以显示如何使用此CodePlex工具提示来解决OP的问题?
<Style x:Key="TipHelp" TargetType="ToolTip">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<TextBlock Text="{Binding SomeOtherProperty}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>