Welcome to Pete Brown's 10rem.net

First time here? If you are a developer or are interested in Microsoft tools and technology, please consider subscribing to the latest posts.

You may also be interested in my blog archives, the articles section, or some of my lab projects such as the C64 emulator written in Silverlight.

(hide this)

Quick Tip: Applying Text Options throughout your WPF 4 Application

Pete Brown - 07 June 2010

I recently put together a post showing how the font you select and the text rendering options you set can make a real difference in how text appears in your application. If you want to use the Display, ClearType combination to get GDI-compatible text rendering, you were probably thinking you had to make a huge number of changes throughout your application.

Luckily, that's not the case.

Setting the Text Options is as simple as applying the attached properties to your Window classes in your application.

<Window x:Class="WpfApplication35.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"
        TextOptions.TextRenderingMode="ClearType"
        FontFamily="Segoe UI">

If you have your own base Window-derived class that you use for all your windows, it's even easier: just set it on the base class, and you're done.

image

You can also apply the options to any global styles if that works better for you. This can be especially helpful if you have custom theme support in your application.

Of course, you can do the same for other text rendering options should you want to choose a different set of options. WPF gives you want you need to render text the way you want to, appropriate to your application's requirements.

   
posted by Pete Brown on Monday, June 7, 2010
filed under:    

Comment on this Post

Remember me