WPF在资源内嵌入字体


 图片
比如需要有这种电子表的字体风格--这种样式叫 :longzhoufeng 字体 在微软的字体有 Quartz MS.TTF或者Quartz Regular.TTF字体。下面以Quartz Regular.TTF为例
找到 Quartz Regular.TTF字体文件,把它添加到WPF工程的Resources内,并设置成Resource类型。
写一个FontStyle.xaml 的 字体资源 

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"                    
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>

 

http://www.th7.cn/Program/WPF/201506/489768.shtml


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM