如何在 Xamarin Forms 中使用 Font Awesome 进行代码隐藏?
How can I code-behind use Font Awesome in Xamarin Forms?
我在使用 Font Awesome 文本创建表单时遇到困难。当我在 .xaml 文件中执行时,一切正常,如下所示:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
x:Name="contentPage"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="myappname.Main">
<Label Text=""
FontFamily="Font Awesome 5 Free-Solid-900.otf#Regular"
FontSize="40" />
</ContentPage>
结果是:
资产目录:
我没有为 iOS 创建我的应用程序,所以我没有添加任何额外的配置,即配置 ResourceDictionary。这是我在 Main.xaml.cs 中尝试过的方法(我将展示三种方法,因为我不确定它应该如何工作):
protected override async void OnAppearing()
{
Label newLabel = new Label()
{
Text = "",
FontFamily = "Font Awesome 5 Free-Solid-900.otf#Regular",
FontSize = 40
};
contentPage.Content = newLabel;
}
protected override async void OnAppearing()
{
Label newLabel = new Label()
{
Text = "",
FontFamily = "Font Awesome 5 Free-Solid-900.otf#Font Awesome 5 Free-Solid-900.otf",
FontSize = 40
};
contentPage.Content = newLabel;
}
protected override async void OnAppearing()
{
Label newLabel = new Label()
{
Text = "",
FontFamily = "Font Awesome 5 Free-Solid-900.otf#Font Awesome 5 Free-Solid-900",
FontSize = 40
};
contentPage.Content = newLabel;
}
他们每个人的结果是:
我做错了什么?
尝试使用 \u 而不是
所以它应该是这样的:
Text = "\uf00c",
我在使用 Font Awesome 文本创建表单时遇到困难。当我在 .xaml 文件中执行时,一切正常,如下所示:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
x:Name="contentPage"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="myappname.Main">
<Label Text=""
FontFamily="Font Awesome 5 Free-Solid-900.otf#Regular"
FontSize="40" />
</ContentPage>
结果是:
资产目录:
我没有为 iOS 创建我的应用程序,所以我没有添加任何额外的配置,即配置 ResourceDictionary。这是我在 Main.xaml.cs 中尝试过的方法(我将展示三种方法,因为我不确定它应该如何工作):
protected override async void OnAppearing()
{
Label newLabel = new Label()
{
Text = "",
FontFamily = "Font Awesome 5 Free-Solid-900.otf#Regular",
FontSize = 40
};
contentPage.Content = newLabel;
}
protected override async void OnAppearing()
{
Label newLabel = new Label()
{
Text = "",
FontFamily = "Font Awesome 5 Free-Solid-900.otf#Font Awesome 5 Free-Solid-900.otf",
FontSize = 40
};
contentPage.Content = newLabel;
}
protected override async void OnAppearing()
{
Label newLabel = new Label()
{
Text = "",
FontFamily = "Font Awesome 5 Free-Solid-900.otf#Font Awesome 5 Free-Solid-900",
FontSize = 40
};
contentPage.Content = newLabel;
}
他们每个人的结果是:
我做错了什么?
尝试使用 \u 而不是
所以它应该是这样的:
Text = "\uf00c",