WPF:如果我对父项使用drophadow效果,为什么文本和元素会模糊

Smo*_*lla 21 wpf xaml blur dropshadow

如果我DropShadowEffect向父元素添加一个子元素的文本是模糊的.为什么?

<Grid>
    <Grid.Effect>
        <DropShadowEffect />
    </Grid.Effect>
    <Grid.ColumnDefinitions>
        <ColumnDefinition />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition />
    </Grid.RowDefinitions>
    <TextBlock Background="White">Test</TextBlock>
</Grid>
Run Code Online (Sandbox Code Playgroud)

更新:

与阴影

在此输入图像描述

没影子

在此输入图像描述

Pat*_*lug 43

文本模糊的原因是因为效果会导致元素和所有子元素首先呈现为位图.这意味着无法进行子像素渲染(ClearType),因此文本看起来质量较低.

您可以通过将效果仅应用于可视树的某些部分来解决此问题.不包含文本的部分.

在你的情况下,你可能想要这样的东西:

<Grid>
    <Border>
        <Border.Effect>
            <DropShadowEffect />
        </Border.Effect>
    </Border>
    <TextBlock Background="White">Test</TextBlock>
</Grid>
Run Code Online (Sandbox Code Playgroud)

  • 你也可以试试`<DropShadowEffect RenderingBias ="Quality"/>`这对我有所帮助. (4认同)

小智 21

这可能是子像素的问题.

尝试添加UseLayoutRounding = "True"到网格中.