WPF 工具提示 ControlTemplate 不显示内容

标签 wpf xaml tooltip controltemplate contentpresenter

我已将以下控件模板和样式设置为应用程序中所有工具提示的默认样式:

<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/

相关文章:

c# - 当不同程序集中的 App.xaml 时,Visual Studio 2012 XAML 设计器不显示正确的内容

javascript - 显示隐藏的 div 元素的 jquery 工具提示?

c# - WPF 中的嵌入式字体不起作用

c# - 将 ARGB 拆分为字节值

wpf - 在wpf中使用transformgroup会出现错误

c# - 页面加载时正在 ListView 中选择项目

c# - 标签可见性。折叠在空白内容WPF MVVM上

javascript - 如何向 Foundation 6 工具提示添加少量图像

Delphi/RAD Studio 工具提示扩展 View

c# - 处理文本框中的 Shift-Enter 事件