Much Improved .NET 4.0 WPF Text Rendering

In .NET 4.0 WPF text rendering has been greatly improved.

However this new feature is not enabled by default.

You can read the complete feature write up on the WPF Text Blog.

The scenario where you get the most payback for using this feature is with text that is sized 15pt and below.

Line of Business forms containing TextBlocks, Labels, CheckBoxes, RadioButtons, Buttons and TextBoxes will have FontSizes below 15pt and will receive the most benefit of this new feature.

The feature is enabled by placing the “TextOptions.TextFormattingMode” attached property on the UI Element or on a parent UI Element.

<TextBlock Text=".NET 3.5 rendering" />
        
<TextBlock Text=".NET 4.0 improved rendering" TextOptions.TextFormattingMode="Display" />

The below XAML demonstrates how to have all text rendering use the new text rendering feature by placing the “TextOptions.TextFormattingMode” attached property on the Window.

In the below example, all child controls of the Window will use the new text rendering.

<Window x:Class="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" 
    TextOptions.TextFormattingMode="Display">
    <Grid>

        <TextBlock Text="Inherited the .NET 4.0 improved rendering" />

    </Grid>
</Window>

Visual Studio 2010 Beta2 and .NET 4.0 have a lot of new goodness, go check it out!

Have a great day,

Just a grain of sand on the worlds beaches.

7 Responses to Much Improved .NET 4.0 WPF Text Rendering

  1. graemekh says:

    Now someone needs to come up with an easy way to set a style or something that causes your text to automatically choose the optimal TextFormattingMode based on the size of the text. :)

  2. [...] Much Improved .NET 4.0 WPF Text Rendering « Karl On WPF – .Net karlshifflett.wordpress.com/2009/10/22/much-improved-net-4-0-wpf-text-rendering – view page – cached The scenario where you get the most payback for using this feature is with text that is sized 15pt and below. — From the page [...]

  3. [...] Much Improved .NET 4.0 WPF Text Rendering (Karl Shifflett) [...]

  4. danielvaughan says:

    Thanks for the tip Karl.
    Is it for performance reasons that it is not enabled by default?

    • Daniel,

      This is the topic of much debate (still being debated).

      For forms based Line of Business applications “Display” is a good default.

      Compat with .NET 3.5 is one reason why its not on by default.

      The referenced blog post only lists one sceanario where “Display” is the optimal choice.

      Have another look at the TextFormattingMode Usage paragraph in the link.

      It comes down to the type of application you are writing, Font Sizes and in some cases the customers display devices.

      Cheers,

      Karl

      • danielvaughan says:

        Ah yes, thanks. I see there are other advantages such as spacing with large text.

        Cheers,
        Daniel

Follow

Get every new post delivered to your Inbox.

Join 248 other followers