This is kind of driving me insane. Adding a DropShadowEffect
to a button. In the IDE it looks like this:
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:
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:
Yet once again in the IDE it looks fine:
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"
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With