WPF Dropshadow on Button causes blurry text

Xaphann picture Xaphann · Feb 3, 2014 · Viewed 12k times · Source

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

Answer

Mike Strobel picture Mike Strobel · Feb 3, 2014

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".