1、《WPF编程宝典》第6章
2、嵌入字体文件
3、XAML
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Name="pnl1" Margin="5">
<Button Name="cmd1">Command 1</Button>
<Button Name="cmd2">Command 2</Button>
<Button Name="cmd3">Command 3</Button>
<CheckBox Name="cb1">选中</CheckBox>
<Label Name="lbl1" FontSize="20">嵌入字体测试1</Label>
<Label Name="lbl2" FontFamily="./#Fixedsys" FontSize="20">嵌入字体测试2</Label>
<TextBlock TextDecorations="Underline">Underlined text</TextBlock>
<Button FontFamily="Technical Italic, Comic Sans MS, Arial">A Button</Button>
</StackPanel>
<ListBox Grid.Row="1" Name="lstFonts" ScrollViewer.VerticalScrollBarVisibility="Visible" SourceUpdated="LstFonts_SourceUpdated">
</ListBox>
</Grid>
4、代码
private void InitUI()
{
cmd1.Background = new SolidColorBrush(Colors.AliceBlue);
cmd1.BorderBrush = new SolidColorBrush(Colors.Yellow);
cmd1.BorderThickness = new Thickness(5, 5, 5, 5);
foreach (FontFamily ft in System.Windows.Media.Fonts.SystemFontFamilies)
{
lstFonts.Items.Add(ft.Source);
}
}
private void LstFonts_SourceUpdated(object sender, DataTransferEventArgs e)
{
Decorator decorator = (Decorator)VisualTreeHelper.GetChild(lstFonts, 0);
ScrollViewer scrollViewer = (ScrollViewer)decorator.Child;
scrollViewer.ScrollToEnd();
}