Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Dropshadow on Button causes blurry text

Tags:

c#

wpf

dropshadow

This is kind of driving me insane. Adding a DropShadowEffect to a button. In the IDE it looks like this:

enter image description here

Second button is for reference with no DropShadowEffect. As you can see there next no difference. Then I build the project and when it runs it looks like this:

enter image description here

What is causing this change? Here is the XAML for the two buttons:

<Button Name="clearButton" Content="Clear" Click="clearButton_Click" Margin="5,0,5,0" MaxWidth="80" MinHeight="40" 
    TextOptions.TextFormattingMode="Display">
<Button.Effect>
    <DropShadowEffect BlurRadius="5" ShadowDepth="3" />
</Button.Effect>
</Button>
<Button Content="Clear" Margin="5,5,5,0" MaxWidth="80" MinHeight="40"  TextOptions.TextFormattingMode="Display" />

Edit: Taking @gretro does make it look better but it still is not right:

enter image description here

Yet once again in the IDE it looks fine:

enter image description here

like image 894
Xaphann Avatar asked Feb 03 '14 21:02

Xaphann


2 Answers

Your entire button is rendering on a cross-pixel boundary. Note how the 1-point border actually spans multiple pixels, causing a blurring effect.

Try setting UseLayoutRounding="True" on a parent or ancestor element. The further up the tree, the better (your view's root visual would be ideal). You can also try SnapsToDevicePixels="True".

like image 193
Mike Strobel Avatar answered Oct 17 '22 10:10

Mike Strobel


Remove the attached Property TextOptions.TextFormattingMode="Display". This is what is causing the button to be blurry.

<Button Grid.Row="25" Grid.Column="0" Content="Clear">
    <Button.Effect>
       <DropShadowEffect BlurRadius="5" ShadowDepth="3" />
    </Button.Effect>
</Button>

This XAML renders crystal clear text in the button with the shadow effect for me.

like image 36
gretro Avatar answered Oct 17 '22 11:10

gretro