15.02.2015 Views

C# 4 and .NET 4

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

1076 ❘ ChaPTer 37 creAtinG dOcuments with wpf<br />

➤<br />

➤<br />

➤<br />

➤<br />

FontStyle values are defined by the FontStyles class that offers Normal, Italic, <strong>and</strong> Oblique.<br />

With FontStretch you can specify the degrees to stretch the font compared to the normal aspect<br />

ratio. FrontStretch defines predefined stretches that range from 50% (UltraCondensed) to<br />

200% (UltraExp<strong>and</strong>ed). Predefined values in between the range are ExtraCondensed (62.5%),<br />

Condensed (75%), SemiCondensed (87.5%), Normal (100%), SemiExp<strong>and</strong>ed (112.5%), Exp<strong>and</strong>ed<br />

(125%), ExtraExp<strong>and</strong>ed (150%)<br />

FontSize is of type double where you can specify the size of the font in device-independent units,<br />

inches, centimeters, <strong>and</strong> points.<br />

With FontFamily you define the name of the preferred font-family, e.g., Arial or Times New Roman.<br />

With this property you can specify a list of font family names so if one font is not available, the next<br />

one in the list is used. (If neither the selected font nor the alternate font are available, a flow document<br />

falls back to the default MessageFontFamily.) You can also reference a font family from a resource<br />

or use a URI to reference a font from a server. With fixed documents there’s no fallback on a font not<br />

available because the font is available with the document.<br />

To give you a feel for the look of different fonts, the following sample WPF application includes a ListBox.<br />

The ListBox defines an ItemTemplate for every item in the list. This template uses four TextBlock<br />

elements where the FontFamily is bound to the Source property of a FontFamily object. With different<br />

TextBlock elements FontWeight <strong>and</strong> FontStyle are set:<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

code snippet ShowFonts/ShowFontsWindow.xaml<br />

In the code-behind, the data context is set to the result of the SystemFontFamilies property of the<br />

System.Windows.Media.Font class:<br />

public partial class ShowFontsWindow : Window<br />

{<br />

public ShowFontsWindow()<br />

{<br />

InitializeComponent();<br />

}<br />

}<br />

this.DataContext = Fonts.SystemFontFamilies;<br />

code snippet ShowFonts/ShowFontsWindow.xaml.cs<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!