Reputation: 4577
There is a criticism of one of my applications. The displayed text is perceived as blurry. I zoomed the window somewhat and got this result (so they are right)
resulting from what I've tried here in this simplified example:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<StackPanel>
<TextBlock Text="StatusDTC [1]"></TextBlock>
<TextBlock Text="StatusDTC [2]"
RenderOptions.BitmapScalingMode="NearestNeighbor"
RenderOptions.EdgeMode="Aliased"></TextBlock>
<TextBlock Text="StatusDTC [3]"
SnapsToDevicePixels="True"></TextBlock>
<TextBlock Text="StatusDTC [4]"
SnapsToDevicePixels="True"
RenderOptions.BitmapScalingMode="NearestNeighbor"
RenderOptions.EdgeMode="Aliased"></TextBlock>
</StackPanel>
</Grid>
</Window>
I found something similar here. but UseLayoutRounding seems to be not available for .Net 3.5. I googled a bit and found that there are improvements in .Net 4 (TextOptions.TextRenderingMode) addressing this issue, but switching to .Net 4 with this application is not an option.
As I know that Win7 renders WPF different than XP, I also started a virtual XP and tried it there. The result is the same.
Does someone have an idea to crisp the text in .Net 3.5?
Upvotes: 1
Views: 870
Reputation: 14567
If upgrading to .NET 4.0 is absolutely not an option, there's one last (slightly desperate) option you could consider: get something else to render the text. For example, you could use, say, GDI+ to render the text you need to a bitmap and then display that. Or you could use interop to host a Windows Forms Label control.
These are both truly horrible solutions (which is why I've only suggested this after you confirmed in the comments that using a recent version of WPF is simply not an option). The interop one will lead to all the usual HWND interop problems (i.e, the Label will get its own HWND, meaning that it will be rendered completely separately from the WPF content, which might lead to obvious visual discontinuities.)
So if I were stuck in this situation I think I'd look at the option of rendering to a bitmap. It's possible to use GDI+ to produce a bitmap which you can then render with a WPF Image element. And if you were prepared to write a custom control to do this you could even support things like data binding (by defining a Text dependency property for the text you render). It's not straightforward though - although there is common ground in terms of support for Windows bitmaps, transferring the data from the GDI+ world to WIC (Windows Imaging Components, which is what WPF relies on for its bitmap handling) is...messy. Also, if you have any need to support accessibility (e.g., making the text visible to screen readers, supporting mnemonic access keys etc.) then this becomes a relatively complex undertaking.
Upvotes: 2
Reputation: 172478
As explained in the link from Ameen's answer, this problem is mostly seen at small font sizes.
Is increasing the font size an option for you? I know that this is more a workaround than a solution, but it's a quick and easy way to get rid of the blurryness if you cannot move away from Framework 3.5.
Upvotes: 1
Reputation: 2586
I don't think short of using a Bitmap font you can do anything here. :( BitmapScalingMode
should not affect your current example as long as the font you are using is Vector based, you really do want the 4.0 text improvements
In Windows 7, the text drawing was switched to DWrite and that's why it's different than XP.
Upvotes: 3