如何在XAML/C#中显示超棒的字形 [英] How can I display a font awesome glyph in XAML/C#

查看:109
本文介绍了如何在XAML/C#中显示超棒的字形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Visual Studio中尝试了很多东西,但是仍然无法显示字形.

I have tried many things in Visual Studio, but I still can not display a glyph.

  1. 我需要添加一个NuGet软件包吗?哪个?
  2. 我需要一个使用..."吗?在C#中?
  3. 我需要在XAML中使用'xmlns:...'吗?
  4. 我应该用标签"显示它吗?

我知道在HTML中,您只需向您的元素添加一个类.但是我对XAML感到困惑. (它是跨平台的,对吧?)

I know in HTML, you just add a class to your element. But I am stumped in XAML. (It's cross-platform, right?)

这应该是一件简单的事情,但是我无法获得功能的任何答案.如果可以的话,请提供答案并回答所有要点.

This should a simple thing but I can not get any answers to function. Please provide an answer if you can do this and answer all points.

推荐答案

有正确的 Xamarin.Forms的插件.该插件不仅具有FontAwesome字体.

There is a correct plugin for Xamarin.Forms. This plugin not only has FontAwesome Font.

根据 github中的示例,您必须执行以下:

According to this example in github you must do the following:

<StackLayout Orientation="Horizontal">
        <iconize:IconLabel FontSize="20" Text="{Binding Key}" TextColor="Green" VerticalTextAlignment="Center" />
</StackLayout>

[UPDATE]

根据user3247130的要求,我留下了完整的示例:

On request from user3247130 I leave the complete example:

从Visual Studio或Xamarin Studio中,安装以下软件包:

From Visual Studio or Xamarin Studio, install the following packages:

  • Xam.Plugin.Iconize
  • Xam.Plugin.Iconize.FontSwesome
  • Xam.FormsPlugin.Iconize

在Android项目的MainActivity类的OnCreate()方法中添加:

In the Android project, MainActivity class, OnCreate() method add:

FormsPlugin.Iconize.Droid.IconControls.Init(Resource.Id.toolbar);
Plugin.Iconize.Iconize.With(new Plugin.Iconize.Fonts.FontAwesomeModule());

在iOS项目的AppDelegate类FinishedLaunching()方法中,添加类似的行:

In the iOS project, AppDelegate class, FinishedLaunching() method, add similar lines:

FormsPlugin.Iconize.iOS.IconControls.Init();
Plugin.Iconize.Iconize.With(new Plugin.Iconize.Fonts.FontAwesomeModule());

此外,在iOS项目中,添加info.plist

Also, in iOS project, info.plist add

<key>UIAppFonts</key>
<array>     
    <string>iconize-fontawesome.ttf</string>
</array>

现在,在具有工具栏的XAML中,在标签中添加

Now, in your XAML where your have your toolbar, in tag, add

<ContentPage ...
xmlns:iconize="clr-namespace:FormsPlugin.Iconize;assembly=FormsPlugin.Iconize">

<iconize:IconLabel Text="fa-search"  />

[UPDATE 2]

此插件在UWP平台上有问题. 要在UWP平台上运行此插件,请按照以下步骤操作:

This plugin has an issue on UWP platform. To run this plugin on UWP platform follow these steps:

首先,在%userprofile%\.nuget\packages\xam.plugin.iconize.fontawesome‌​\2.0.0.29-beta\lib\U‌​AP10\

第二,在Plugin.Iconize.FontAwesome.UWP文件夹中创建另一个名为Assets的文件夹

Second, create another folder called Assets into Plugin.Iconize.FontAwesome.UWP folder

将名为Fonts的另一个文件夹创建到Assets文件夹

Third create anoother folder called Fonts into Assets folder

最后复制 iconize- fontawesome.ttf 文件(您不应更改其名称).

And finally copy iconize-fontawesome.ttf file (you shouldn't change their name).

此外,您还必须在UWP项目的资产文件夹中添加 Fonts 文件夹,然后粘贴相同的ttf文件

Additionally, you have to add a Fonts folder in the Assets folder in your UWP project and then paste the same ttf file

在Android或iOS上这不是必需的,这只是UWP平台的问题

This is not necessary on Android or iOS it is only a issue of the UWP platform

这篇关于如何在XAML/C#中显示超棒的字形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆