WPF Choose Font Dialog

WPF still doesn’t provide out of the box common Font Chooser dialog, and I can’t realize if Microsoft is going to provide such the dialog in the forthcoming WPF 4.0 version.

Currently we have the following alternatives:

  1. Microsoft Windows SDK provides the WPFNotepad sample where the Sample FontChooser is implemented. This implementation conforms to recommendations in the WPF Font Selection Model whitepaper.
  2. Sample Font Chooser by Niklas Borson.
  3. Pure XAML Font Chooser by Norris Cheng.

The former two items are full-fledged Font Chooser dialog implementations, and the latter one is the sample of how to implement the basic Font Chooser in pure XAML. Maybe there are other implementations but I could not find them.

From full-fledged options I prefer the one of Niklas Borson: it has more compact design and, as much as I tested it, all its features work fine. The only drawback is that the dialog initialization takes too much time.

There are things I don’t like in both the first and the second implementations: they are written rather in the Windows Forms style than in the WPF one. The dialog controls and layout are defined in the XAML. All the logic is implemented in the dialog code behind file, and this file is long and complicated. There is no one Binding object used!

I have rewrote the Font Chooser dialog basing on the approach close to the MVC pattern: there is the Font properties class, the Model, and the dialog controls binds to the properties of this model class in XAML. The code behind file contains as little code as possible. The implementation consists of the following main parts:

  • FontInfo class contains the set of properties describing the Font in the WPF world. FontInfo class plays the role of the Model in the MVC pattern.
  • The dialog contains a lot of controls defined in the ChooseFont.xaml which represent the View. These controls are bound to the Font properties defined in the FontInfo class.
  • ChooseFont.xaml.cs file code provides the constructors, OK button handler and some event handlers implementing the auto complete behavior in the dialog.

You can download the dialog source code here:

Oleg V. Polikarpotchkin

Technorati Теги: ,,,

About ovpwp

I am engaged in programming, maintenance and supply of computing technique since 1970. Started with the computers M, BESM, Minsk series and received appropriate education in the least, in which it was then possible in THE USSR. Then he went the usual way - ES series, IBM 360/370, Sun Spark, Ibm Power & PS2, PC. Programming started in the code (machine commands), then were sorts of assemblers, Algol, FORTRAN, PL/1, C, C , VB, C#. It is only the ones that I used the production scale; but there were, of course, others like List, Modula, Pascal, Java, etc. Currently I prefer .NET platform for desktop development. I don't really like web-programming (probably because of the inability for quality design), but I have enough experience in site building in LAMP environment using PHP.
This entry was posted in Uncategorized. Bookmark the permalink.

3 Responses to WPF Choose Font Dialog

  1. Unknown says:

    This blog is very informative. I love blogging when it is for or about something I believe in. I also read news blogs often and find that it makes me feel more intelligent every time I read them. I also feel like I am a pretty good person who tries to treat others with respect, no matter what their opinion is. There are some real haters out there. Thanks again. I learned a few things about blogging. I will definitely put your site on my speed dial.Thankshttp://www.vanjobb.huhttp://www.vanjobb.hu/mobilinternet.php?11http://www.vanjobb.hu/Bankbetetkamatok.php?22http://www.vanjobb.hu/nevnapokdatumszerint.php?39http://www.vanjobb.hu/nevnapoknaptar.php?41http://www.vanjobb.hu/nevnapok.php?40

  2. Vadim says:

    Really Nice component. In the project properties it is said that ChooseFontDialog is Windows apllication, so .exe. I tried to convert it to .dll project but unfortunately failed =(
    Is it a specific feature of your implementation ?

    • Vadim says:

      To convert choosefontdialog project to dll ypu need to delete some properties from .csproj file. Something like ApplicationDefinition.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s