Sample Font Chooser

[ Reposting, as this entry got deleted accidentally. Aplogies if you’ve seen this before! ] 

One thing we didn’t have time to include in the first release of WPF is a set of predefined dialogs analogous to the Win32 common dialogs. Attached to this article is a sample application that might help you implement your own font chooser.

This is not the first font chooser posted to this blog. Norris posted a XAML-only version in June, which was an impressive demonstration of how much can be accomplished in just a few lines of XAML with data binding. This version is not as admirably brief but is more full-featured, including not just family and typeface but text decorations, font information, and all the typographic properties. Here is a screen shot:

Sample font dialog screen shot

Note that you could get away with using the Win32 common dialogs for file-open, etc., but fonts are different because the font selection model is different in WPF than in GDI. For a good example of this, look at the Arial font family in the sample font chooser and in Notepad’s font dialog box.

In WPF (i.e., the sample font chooser), Arial includes the typefaces Regular, Italic, Bold, Bold Italic, Narrow, and Black, plus the simulated faces Oblique, Bold Oblique, Narrow Oblique, and Black Oblique. In GDI (i.e., Notepad’s font dialog box), Arial includes just Regular, Italic, Bold, and Bold Italic. The narrow faces are treated as a separate font family (“Arial Narrow”) because GDI doesn’t allow members of a font family to be differentiated by width. Likewise, the black faces are treated as a separate font family (“Arial Black”) because GDI supports only two weights with a family: bold and not-bold.

The attached sample code is provided as is. I won’t promise it’s perfect, but I hope it helps you get started. Enjoy!

–Niklas Borson

Comments (8)

  1. The very first application I attempted to write in WPF was a utility to help me with choosing fonts.

  2. The very first application I attempted to write in WPF was a utility to help me with choosing fonts.

  3. HaroldMetcalf says:

    This is really neat.  I downloaded it, compiled it, and it works!  I am a happy camper!

  4. azmo says:

    呵呵,god job, WPF need a fontdialog.

  5. Breakable says:

    It it amazing there is no Font container object to store all those properties:


















































  6. Jgdai says:

    perfect! I want to learn more about it.

  7. gcadmes says:

    I realize this post is several years old (7) to be exact…. however, I thought I'd take a chance and ask a question regarding the font script-character sets.

    In the System.Windows.Forms.FontDialog, there is a combo box that lists the Scripts for the selected FontFamily character set.

    Does anyone know what the API is to get the available scripts for the selected Fontfamily?

    Thanks much,


  8. Enki's Wingmaker says:

    找不到 Draft.PresentationDesignMarkup, Version=0.0.4030.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL