WPF在资源内嵌入字体

  图片
比如需要有这种电子表的字体风格--这种样式叫 :longzhoufeng 字体 在微软的字体有  Quartz MS.TTF或者 Quartz Regular.TTF字体。下面以 Quartz Regular.TTF为例
找到 Quartz Regular.TTF字体文件,把它添加到WPF工程的Resources内,并设置成Resource类型。
写一个FontStyle.xaml 的 字体资源 
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Style x:Key="Quartz Regular">
        <Setter Property="TextElement.FontFamily" Value="/Resources/#Quartz Regular"/>
    </Style>
</ResourceDictionary>

字体使用中将字体作为字体样式来引用
<Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Resources/FontStyle.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>  
<Grid Background="#2a3747">
        <Label Content="5201314" HorizontalAlignment="Left" FontSize="34" VerticalContentAlignment="Center" Height="60" Margin="101,77,0,0" VerticalAlignment="Top" Width="286" Foreground="GreenYellow" Style="{DynamicResource 'Quartz Regular'}" />
        <Label Content="lovessea@sina.com" HorizontalAlignment="right" Foreground="White" Height="29" Margin="379,291,0,0" VerticalAlignment="Top" Width="128"/>
</Grid>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值