Question

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

Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top