在Windows Phone 8应用程序中添加字体真棒

本文关键字:添加 字体 应用程序 Windows Phone | 更新日期: 2023-09-27 17:56:58

我正在Windows Phone 8应用程序中使用Font Awesome。我在数据库中添加了一部分 unicode(例如 f000 )。在我的代码中,我添加了"''u"来完成 unicode。我像这样添加它:

_model.ContentImage = @"'u" + rec.UniContentImage;

当我调试它并添加断点时,contentimage填充了"''uf000"(在调试器中)。并且字体不会显示。当我将内容图像(在调试器中)中的内容更改为"'uf000"很棒的字体正确显示时。

有谁知道我如何在 c# 中正确和动态地添加字体很棒?

在Windows Phone 8应用程序中添加字体真棒

这将加载 FontAwesome 自定义字体以在 Windows 8.1 通用应用中使用:

FontFamily customFont = new FontFamily("ms-appx:///Assets/FontAwesome.otf#FontAwesome");
textBlock.FontFamily = customFont;
textBlock.Text = "'uf164"; // thumbs up!

注意:设置"FontAwesome.otf"属性:

  • 构建操作:"内容"
  • 复制到输出目录:"不复制"

这里还有我用来返回绑定的 Unicode 字符串的数据模型方法(其中 this.code 是 "''uf164"):

public String unicode
    {
        get
        {
            String codePoint = this.code.Substring(2); // remove ''u' => "f164";
            int unicode = int.Parse(codePoint, System.Globalization.NumberStyles.HexNumber);
            String unicodeString = char.ConvertFromUtf32(unicode).ToString();
            return unicodeString; // "'uf164"
        }
    }