Binding ListBox ItemsSource to Fonts.SystemFontFamilies
<Window x:Class="FontViewer.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Teach Yourself WPF: Font Viewer"
Height="480"
Width="640">
<DockPanel Margin="8">
<ListBox x:Name="FontList"
DockPanel.Dock="Left"
ItemsSource="{x:Static Fonts.SystemFontFamilies}"
Width="160" />
<TextBox x:Name="SampleText"
DockPanel.Dock="Bottom"
MinLines="4"
Margin="8 0"
TextWrapping="Wrap">
<TextBox.ToolTip>
<TextBlock>
<Italic Foreground="Red">Instructions: </Italic>
Type here to change the preview text.
</TextBlock>
</TextBox.ToolTip>
The quick brown fox jumps over the lazy dog.
</TextBox>
<StackPanel Margin="8 0 8 8">
<TextBlock Text="{Binding ElementName=SampleText, Path=Text}"
FontFamily="{Binding ElementName=FontList,Path=SelectedItem}"
FontSize="10"
TextWrapping="Wrap"
Margin="0 0 0 4" />
<TextBlock Text="{Binding ElementName=SampleText, Path=Text}"
FontFamily="{Binding ElementName=FontList,Path=SelectedItem}"
FontSize="16"
TextWrapping="Wrap"
Margin="0 0 0 4" />
<TextBlock Text="{Binding ElementName=SampleText, Path=Text}"
FontFamily="{Binding ElementName=FontList,Path=SelectedItem}"
FontSize="24"
TextWrapping="Wrap"
Margin="0 0 0 4" />
<TextBlock Text="{Binding ElementName=SampleText, Path=Text}"
FontFamily="{Binding ElementName=FontList,Path=SelectedItem}"
FontSize="32"
TextWrapping="Wrap" />
</StackPanel>
</DockPanel>
</Window>
Related examples in the same category