一、图标字体

       阿里巴巴开源字体网址:http://www.iconfont.cn/

      使用方法:

       1、新浪微博账号登录

       2、点击图标 -> "添加入库"

       3、库->下载代码

            界面如下:

WPF自定义控件与样式(1) - 图标字体



      WPF自定义控件与样式(1) - 图标字体

4、下载的代码中的 *.ttf 文件,在WPF中用

      文件如下:

      WPF自定义控件与样式(1) - 图标字体

WPF自定义控件与样式(1) - 图标字体

     

二、WPF 中使用图标字体

1、iconfont.ttf 添加到Resources文件夹

      iconfont.ttf属性如下:

    WPF自定义控件与样式(1) - 图标字体


2、XAML代码

<Window x:Class="WpfApplication2.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <Style x:Key="FIcon" TargetType="TextBlock">
            <Setter Property="FontFamily" Value="/程序集名称;component/Resources/#iconfont"></Setter>
            <Setter Property="Foreground" Value="Green"></Setter>
            <Setter Property="TextAlignment" Value="Center"/>
            <Setter Property="HorizontalAlignment" Value="Center"/>
            <Setter Property="VerticalAlignment" Value="Center"/>
            <Setter Property="FontSize" Value="20"/>
        </Style>
    </Window.Resources>
        <StackPanel>
        <TextBlock Text="&#xe607;" Style="{StaticResource FIcon}" FontSize="30" Margin="3" ></TextBlock>
        <TextBlock Text="&#xe612;" Style="{StaticResource FIcon}" FontSize="30" Margin="3" ></TextBlock>
    </StackPanel>
</Window>


效果:

WPF自定义控件与样式(1) - 图标字体


相关文章: