如何在工具提示上获得更厚的阴影?

时间:2011-12-16 07:55:46

标签: c# wpf xaml tooltip

我用以下内容覆盖了我的工具提示:

<Style x:Key="{x:Type ToolTip}" TargetType="ToolTip">
    <Setter Property="OverridesDefaultStyle" Value="True"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ToolTip">
                <Grid>
                    <Grid.Background>
                        <SolidColorBrush />
                    </Grid.Background>
                    <mwt:SystemDropShadowChrome Color="#00FFFFFF" CornerRadius="5" Name="Shdw" SnapsToDevicePixels="True">
                        <Border CornerRadius="5">
                            <StackPanel>
                                <ContentPresenter TextBlock.Foreground="Black" />
                            </StackPanel>
                        </Border>
                    </mwt:SystemDropShadowChrome>
                </Grid>

边距的厚度值似乎最大值为5?

                <ControlTemplate.Triggers>
                    <Trigger Property="ToolTipService.HasDropShadow">
                        <Setter Property="FrameworkElement.Margin" TargetName="Shdw">
                            <Setter.Value>
                                <Thickness>0,0,5,5</Thickness>
                            </Setter.Value>
                        </Setter>
                        <Trigger.Value>
                            <sys:Boolean>True</sys:Boolean>
                        </Trigger.Value>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

能够看到更多的阴影会很高兴。

我没有发布我的所有代码。这是基于来自icebat的响应的编辑:

<Style x:Key="{x:Type ToolTip}" TargetType="ToolTip">
    <Setter Property="OverridesDefaultStyle" Value="True"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ToolTip">
                <Grid>
                    <Grid.Background>
                        <SolidColorBrush />
                    </Grid.Background>
                    <mwt:SystemDropShadowChrome Color="#71000000" CornerRadius="5" Name="Shdw" SnapsToDevicePixels="True">
                        <Border CornerRadius="5">
                            <StackPanel>
                                <ContentPresenter TextOptions.TextRenderingMode="ClearType" TextOptions.TextFormattingMode="Display" TextBlock.FontFamily="Segoe UI" TextBlock.FontStretch="Normal" TextBlock.FontWeight="Normal" TextBlock.Foreground="Black" TextBlock.FontSize="13" Margin="18,8,16,4" HorizontalAlignment="Left" VerticalAlignment="Top" />
                                <Border HorizontalAlignment="Stretch" BorderThickness="0,1,0,0" BorderBrush="Gray" Margin="10,5,10,5"  Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2">
                                    <TextBlock Margin="8,4,0,0" FontWeight="Bold" Text="{x:Static res:AppStrings.Help_0_Footer}" FontSize="13" Foreground="#E3000000" />
                                </Border>
                            </StackPanel>
                            <Border.Background>
                                <LinearGradientBrush>
                                    <LinearGradientBrush.StartPoint>
                                        <Point X=".5" Y="0"/>
                                    </LinearGradientBrush.StartPoint>
                                    <LinearGradientBrush.EndPoint>
                                        <Point X=".5" Y="1"/>
                                    </LinearGradientBrush.EndPoint>
                                    <LinearGradientBrush.GradientStops>
                                        <GradientStop Color="#FFFFA200" Offset="1"/>
                                        <GradientStop Color="White" Offset="0.305"/>
                                    </LinearGradientBrush.GradientStops>
                                </LinearGradientBrush>
                            </Border.Background>
                        </Border>
                    </mwt:SystemDropShadowChrome>
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="ToolTipService.HasDropShadow" Value="True">
                        <Setter Property="Margin" TargetName="Shdw" Value="0,0,5,5"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

对于大于5的边距,我仍然没有得到更厚的阴影。

1 个答案:

答案 0 :(得分:2)

保证金不受限制。要查看更多阴影,您需要将保证金应用于SystemDropShadowChrome装饰器本身,而不是其内容:

<mwt:SystemDropShadowChrome Name="Shdw" CornerRadius="5">
    <Border Name="shdwContent" CornerRadius="5">
         <StackPanel>
             <ContentPresenter TextBlock.Foreground="Black" />
         </StackPanel>
    </Border>
</mwt:SystemDropShadowChrome>
...
<ControlTemplate.Triggers>
    <Trigger Property="ToolTipService.HasDropShadow" Value="True">
        <Setter Property="Margin" TargetName="ShdwContent" Value="0,0,5,5">
    </Trigger>
</ControlTemplate.Triggers>

作为旁注,现在您使用透明色作为阴影颜色(#00FFFFFF)。如果没有通过某些触发器或其他方式改变,你就不会看到任何阴影。