我如何在工具提示上得到一个更厚的投影?

本文关键字:一个 投影 工具提示 | 更新日期: 2023-09-27 18:18:15

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

<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的边距,我仍然没有得到更厚的下拉阴影

我如何在工具提示上得到一个更厚的投影?

不限制页边距。为了看到更多的阴影,你不需要对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)。如果没有通过触发或其他方式改变,则不会看到任何阴影

相关文章: