【发布时间】:2014-11-15 21:30:23
【问题描述】:
我想设置自定义工具提示样式,但仅适用于某些类型的控件。我有一个自定义控件,它设置工具提示的颜色取决于绑定的消息类型。
如果为“工具提示”设置样式,所有工具提示都显示没有边框,但我只想为我的自定义控件设置。
<Style x:Key="{x:Type ToolTip}" TargetType="ToolTip">
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="HasDropShadow" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToolTip">
<ContentPresenter />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
这是我想要的外观和感觉 http://i.imgur.com/fG1aCso.png
“普通工具提示”必须在鼠标悬停在按钮上时显示,“信息工具提示”在带有蓝色文本的自定义控件上时显示,等等
FTI:我尝试将样式放在 DLL(定义自定义控件的位置)上,但不起作用。我的“assembly.info”上有下一个代码,因此它采用了“Themes/Generic.xaml”中的模板
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
【问题讨论】:
-
将
TargetType更改为您的自定义控件,然后将属性ToolTip设置为这种样式? -
如果我更改目标类型,系统会抛出异常。 TargetType 与 System.ArgumentException 不匹配。