问题描述
如果在父元素上添加DropShadowEffect
,则子元素的文本将模糊.为什么?
If I add a DropShadowEffect
to an parent element the text of the child elements are blurred. Why?
<Grid>
<Grid.Effect>
<DropShadowEffect />
</Grid.Effect>
<Grid.ColumnDefinitions>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Background="White">Test</TextBlock>
</Grid>
更新:
有阴影
没有阴影
推荐答案
文本模糊的原因是,Effects首先将元素和所有子元素渲染为位图.这意味着无法进行亚像素渲染(ClearType),因此文本看起来质量较低.
The reason why the text is blurred is because Effects cause the elements and all sub-elements to be rendered into a Bitmap first. This means that sub-pixel rendering (ClearType) cannot take place and therefore the text appears lower-quality.
您可以通过将效果仅应用于视觉树的一部分来解决此问题.不包含文字的部分.
You can work around this by applying the effect to only parts of your visual tree. The parts that don't contain the text.
在您的情况下,您可能想要这样的东西:
In your case you probably want something like this:
<Grid>
<Border>
<Border.Effect>
<DropShadowEffect />
</Border.Effect>
</Border>
<TextBlock Background="White">Test</TextBlock>
</Grid>
这篇关于WPF:如果对父项使用阴影效果,为什么文本和元素会模糊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!