zoukankan      html  css  js  c++  java
  • 【WPF】矢量字体图标(iconfont)使用

    1、字体文件加入到项目资源

    下载字体文件(.ttf),添加到项目中,并设置生成操作为"Resource"。(很重要!!)


    2、定义样式
    使用TextBlock作为图标显示的容器,因此定义一个TextBlock的样式即可,如下所示。其中“SK2015” 为字体名称。

        <Style x:Key="FIcon" TargetType="TextBlock">
            <Setter Property="FontFamily" Value="/K.Framework.Controls;component/Resources/#SF2015"></Setter> 
            <Setter Property="Foreground" Value="{StaticResource TextForeground}"/>
            <Setter Property="TextAlignment" Value="Center"/> 
            <Setter Property="HorizontalAlignment" Value="Center"/>
            <Setter Property="VerticalAlignment" Value="Center"/> 
            <Setter Property="FontSize" Value="20"/> 
        </Style>


    3、使用示例
    (1)方法1
    在XAML中使用,Text的值是字符的Unicode编码。

        <StackPanel Orientation="Horizontal">
            <TextBlock Text="&#xe600;" Style="{StaticResource FIcon}" FontSize="30" Margin="3" ></TextBlock>
        </StackPanel>

    (2)方法2
    在cs文件使用
    this .ticon1.Text = "ue616" ;


    4、ttf文件下载
    Iconfont-阿里巴巴矢量图标库 :http://www.iconfont.cn/
    提供了大量的字体图标(包括网友共享的),可以选择需要的字体,然后打包到一个字体文件,且可以随意修改字符的编码、字体名称等。
    下载后,*.ttf就是我们需要的字体文件,其他是网页使用需要的,demo.html可以作为图例参考,demo.html内容同上图类似。

     

    /*******相与枕藉乎舟中,不知东方之既白*******/
  • 相关阅读:
    算法竞赛入门经典习题2-3 韩信点兵
    ios入门之c语言篇——基本函数——5——素数判断
    ios入门之c语言篇——基本函数——4——数值交换函数
    144. Binary Tree Preorder Traversal
    143. Reorder List
    142. Linked List Cycle II
    139. Word Break
    138. Copy List with Random Pointer
    137. Single Number II
    135. Candy
  • 原文地址:https://www.cnblogs.com/Mars-0603/p/15357559.html
Copyright © 2011-2022 走看看