GPU Effects & Blurry Text
About a month ago, I ran into a weird issue … that literally confounded me … and irked me to no end. The issue was that whenever I applied a drop shadow effect to a border that contained text … the text would blur a little bit.
So, if I did the following:
<Window
x:Class="EffectsAndBlurryText.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Effects and Blurry Text (Good)"
Height="300"
Width="500"
>
<Grid>
<Border
Margin="20"
Background="White"
BorderBrush="DarkBlue"
BorderThickness="3"
CornerRadius="25"
>
<TextBlock
Text="This text is not blurry."
FontSize="24"
TextWrapping="Wrap"
Foreground="DarkBlue"
HorizontalAlignment="Center"
VerticalAlignment="Center"
/>
</Border>
</Grid>
</Window>
I would get nice looking text:
But if I added the drop shadow effect:
<Window
x:Class="EffectsAndBlurryText.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Effects and Blurry Text (Bad)"
Height="300"
Width="500"
>
<Grid>
<Border
Margin="20"
Background="White"
BorderBrush="DarkBlue"
BorderThickness="3"
CornerRadius="25"
>
<Border.Effect>
<DropShadowEffect Color="DarkGray"/>
</Border.Effect>
<TextBlock
Text="Why, oh, why is this text blurry?"
FontSize="24"
TextWrapping="Wrap"
Foreground="DarkBlue"
HorizontalAlignment="Center"
VerticalAlignment="Center"
/>
</Border>
</Grid>
</Window>
I would get blurry text (click on the image to better see the issue):
So, how can we get around this annoying issue? Here is what I came up with: wrap the Border in a Grid and put another Border underneath the one you had originally. Put the BorderBrush and Background on the new Border and apply the drop shadow effect there instead.
Here is the xaml:
<Window
x:Class="EffectsAndBlurryText.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Effects and Blurry Text (Fixed)"
Height="300"
Width="500"
>
<Grid>
<Border
Margin="20"
BorderThickness="3"
CornerRadius="25"
Background="White"
BorderBrush="DarkBlue"
>
<Border.Effect>
<DropShadowEffect Color="DarkGray"/>
</Border.Effect>
</Border>
<Border
Margin="20"
BorderThickness="3"
CornerRadius="25"
>
<TextBlock
Text="Ah, now, the text is not blurry."
FontSize="24"
TextWrapping="Wrap"
Foreground="DarkBlue"
HorizontalAlignment="Center"
VerticalAlignment="Center"
/>
</Border>
</Grid>
</Window>
I would love to hear if anyone has any better ideas to solve this … or just if others have noticed it as well.
I hope this helps someone … I know at least one other person has run into this. See his January 28th blog entry.
Note: this issue seems intermittent at times. In particular, sometimes you can see it only in the designer (both Visual Studio and Blend). However, that being said, it is not just in the designer … I have seen it in running executables.
Update 1: Others seem to have run into this issue as well. There is a current forum post about this, in fact.
Update 2: Initially, I thought this was an NVIDIA driver issue, but others have seen it on ATI cards and Intel integrated solutions. Walt Ritscher says its a known issue. I wonder if it is related to another issue that I’ve had.