WPF 嵌入字体文件

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();
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值