#264 – Specifying Values for FontWeight

You can specify a number of different values for the FontWeight property of a Control, to specify the thickness, or “weight” of a font.  Each possible value is a request to the font for a different thickness.

Listed in order from lightest weight to heaviest, the possible choices for FontWeight are:

  • Thin
  • ExtraLight
  • Light
  • Normal
  • Medium
  • DemiBold
  • Bold
  • ExtraBold
  • Black
  • ExtraBlack

The number of distinct weights that you’ll get will depend on the font.  Many fonts have just two weights–Normal and Bold.  The weight value specified in the FontWeight setting is just a request.  Windows will return a font whose weight best matches the requested weight.

Below is an example with the Arial typeface.  We request all ten different weights, but we see that there are only three different weights for Arial in Windows.

The Segoe UI font has four different weights:

#259 – Setting Typography Properties for Text Rendered with an OpenType Font

WPF includes a Typography class, which allows setting various attached properties for textual elements.  These properties only affect text that is rendered using an OpenType font.

The Typography class lets you specify things like:

  • Superscripts and subscripts
  • Use of capitals and spacing between capitals
  • Ligatures (combined glyphs)
  • Swashes (decorative elements)
  • Alternate glyphs
  • Historical glyphs
  • Proportional spacing for numerals
  • Turning kerning off/on

For example, we can specify that some text be rendered using small capitals, as follows.

		<TextBlock Margin="20" Width="250" Height="55"
		    FontFamily="Constantia" FontSize="14"
		    TextWrapping="Wrap">
			We secure our friends not by accepting favors but by doing them.
			<Run Typography.Capitals="SmallCaps">--Thucydides</Run>
		</TextBlock>