Windows Server 2012 上的自定义 WPF 工具提示中没有投影

No drop shadow in a custom WPF tool-tip on Windows Server 2012

我创建了一个自定义工具提示,其样式定义在 .xaml 文件中,在应用程序启动时或用户更改应用程序主题时加载。因为工具提示由多个控件使用,每个控件只有细微差别,所以我决定创建一个单独的资源字典文件,其中包含所有使用工具提示的控件共有的所有样式定义。另一方面,我将所有特定于控件的样式放在单独的资源字典文件中。这些文件使用合并字典,并引用具有我提到的常见样式的文件。

基础文件包含多个样式定义,其中至少一个定义了样式触发器。当工具提示的依赖项 属性 HasDropShadow 设置为 true 时,触发器会显示阴影。样式在特定于控件的文件中扩展(使用 BasedOn 属性)。

出于某种原因,当我 运行 Windows Server 2012 上的应用程序时,投影不可见。另一方面,当我 运行 Windows 7 上的应用程序时,投影按预期可见。我声明绑定的方式有问题还是 Windows 以任何方式影响工具提示的 HasDropShadow 属性?

请注意,当我直接设置效果 属性 时,不使用触发器,阴影始终可见,即使在 Windows 2012 年也是如此。

您知道是什么导致了这种行为吗?

这是基础 StyleBase_User_ToolTip.xaml 文件(我从中删除了不相关的内容):

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:Client="clr-namespace:Client;assembly=Client">

    <Style x:Key="ToolTipBorderBase" TargetType="Border">
        <Setter Property="Padding" Value="10,10,10,10" />
        <Setter Property="BorderThickness" Value="0" />

        <Setter Property="Background">
            <Setter.Value>
                <ImageBrush ImageSource="Images\User_ToolTip\background_bar.png" />
            </Setter.Value>
        </Setter>

        <!--drop shadow visibility-->
        <Style.Triggers>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=Client:User_ToolTip}, Path=HasDropShadow}" Value="True">
                <Setter Property="Effect">
                    <Setter.Value>
                        <DropShadowEffect BlurRadius="5" Opacity="0.4"/>
                    </Setter.Value>
                </Setter>
            </DataTrigger>
        </Style.Triggers>
    </Style>

    <Style x:Key="ToolTipContent" TargetType="Client:User_ToolTip">
        <Setter Property="ToolTipService.Placement" Value="Left" />
        <Setter Property="StaysOpen" Value="True" />

        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Client:User_ToolTip}">

                    <Border Style="{DynamicResource ToolTipBorder}">
                        <StackPanel Style="{StaticResource ToolTipContentContainer}">
                            ...
                        </StackPanel>
                    </Border>

                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

这里是特定于控件的文件之一:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Client="clr-namespace:Client;assembly=Client">

    <ResourceDictionary.MergedDictionaries>

        <ResourceDictionary Source="StyleBase_User_ToolTip.xaml" />

        <ResourceDictionary>
            <Style x:Key="ToolTipBorder" TargetType="Border" BasedOn="{StaticResource ToolTipBorderBase}">
                <Setter Property="Margin" Value="2,0,8,8" />
            </Style>
        </ResourceDictionary>

    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

谢谢!

我想我找到了答案。在我的示例中,我将投影的触发器绑定到工具提示的内置 HasDropShadow 属性。我在运行时为它分配了一个 True 值,但是 Windows Server 2012 没有显示阴影,而不是 Windows 7.

但是,当我声明一个单独的依赖项 属性 来指示阴影是否应该可见,并将上述触发器绑定到它时,Windows Server 2012 正确显示了阴影.

那么,某些依赖属性的值可能完全由 OS 控制,我说得对吗?

顺便说一句,我忘了说我的 Client:User_ToolTip 是 System.Windows.Controls.ToolTip 的后代。