我已将以下控件模板和样式设置为应用程序中所有工具提示的默认样式:
<Style TargetType="{x:Type ToolTip}">
<!-- Background="Transparent" BorderBrush="Transparent" BorderThickness="0" HasDropShadow="True" -->
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="Placement" Value="Bottom"></Setter>
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid Background="{Binding Source={x:Static visualResources:ThemeManager.Instance}, Path=ThemePageColor}" >
<ContentPresenter Margin="3"></ContentPresenter>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
(上面的代码在Window.Resources中)
在同一个窗口内我有这个控件:
<Button ToolTip="Tooltip Text!" HorizontalContentAlignment="Right" Height="60" Click="_Button_AddCourse_Click"/>
但是当我运行程序时,工具提示没有按应有的方式显示!我只能看到一个橙色矩形(这是 controltemplate 中的 Grid ,橙色是 ThemeManager.Instance.ThemePageColor 属性),但工具提示内没有任何文本。
提前致谢。
最佳答案
抱歉,我当时正试图通过手机匆忙执行此操作,结果错误地把它扔到了评论中。
不管怎样,就改<ControlTemplate>
吧至<ControlTemplate TargetType="ToolTip">
所以它知道你的 ContentPresenter
甚至试图与你交谈,你应该表现得很好。
希望这有帮助,干杯!
附注- 标记回答了这样的问题,以便人们知道您已经解决了问题。
关于WPF 工具提示 ControlTemplate 不显示内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32531459/