Share via


Previewing fonts in WPF with no code or executable

Sometimes I just love loose XAML. It has been around for a long time, but not every developer that works with WPF knows about this feature.

In any case, I wanted to play with fonts and font sizes specifically to see how WPF would render different combinations, and I was able to whip this up in a couple of minutes. You can just paste this content to a text file with a .xaml extension, and off you go.

<StackPanel
 xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
 Margin="8">

<Label>Font Name:</Label>
<ComboBox Name="FontFamilyBox" IsEditable="True"
 ItemsSource='{Binding Source={x:Static Fonts.SystemFontFamilies}}' />

<Label>Font Size:</Label>
<TextBox Text="16" Name="FontSizeBox" />

<RichTextBox
  FontFamily='{Binding ElementName=FontFamilyBox,Path=Text}'
  FontSize='{Binding ElementName=FontSizeBox,Path=Text}'
  >

<FlowDocument>
<Paragraph>
Some simple sample text.
</Paragraph><Paragraph>
Some simple sample text.
</Paragraph><Paragraph>
Some simple sample text.
</Paragraph><Paragraph>
Some simple sample text.
</Paragraph><Paragraph>
Some simple sample text.
</Paragraph><Paragraph>
Some simple sample text.
</Paragraph><Paragraph>
Some simple sample text.
</Paragraph><Paragraph>
Some simple sample text.
</Paragraph><Paragraph>
Some simple sample text.
</Paragraph><Paragraph>
Some simple sample text.
</Paragraph><Paragraph>
Some simple sample text.
</Paragraph>
</FlowDocument>

</RichTextBox>
</StackPanel>

Enjoy!

fontviewer.xaml