WPF工具提示ControlTemplate不显示内容

时间:2015-09-11 20:15:03

标签: 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"/>

但是当我运行我的程序时,工具提示似乎不应该出现!我只能看到一个橙色矩形(这是控制模板中的网格,橙色是ThemeManager.Instance.ThemeColor属性),但工具提示中没有文字。

提前致谢。

1 个答案:

答案 0 :(得分:1)

很抱歉,我很快就试图通过手机进行此操作,并错误地将其投入评论中。

无论如何,只需将<ControlTemplate>更改为<ControlTemplate TargetType="ToolTip">,即可知道您ContentPresenter甚至试图与之交谈,您应该做得好。

希望这有帮助,欢呼!

P.S。 - Mark回答了这样的问题,所以人们知道你已经解决了问题。