我想为我的 Xamarin.Forms 项目添加很棒的字体,我已将其添加到项目中。 然后我将 FontFamily 添加到 Label 中,如下所示:
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid Padding="15">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="9*" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Text="" FontSize="20">
<Label.FontFamily>
<OnPlatform x:TypeArguments="x:String">
<On Platform="iOS" Value="Font Awesome 5 Free" />
<On Platform="Android" Value="fa-regular-400.ttf#Font Awesome 5 Free Regular" />
</OnPlatform>
</Label.FontFamily>
</Label>
<Label Grid.Column="1" Text="{Binding Title}" FontSize="20"/>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
但是当我将这些硬编码的东西更改为这样的可绑定(bind)属性时:
<Label Grid.Column="0" Text="{Binding FontAwesomeIconText}" FontSize="20">
在c#中这样设置
menuItems = new List<DrawerMenuItem>
{
new DrawerMenuItem {Id = MenuItemType.Browse, Title="Browse", FontAwesomeIconText = "" },
new DrawerMenuItem {Id = MenuItemType.About, Title="About" , FontAwesomeIconText = ""}
};
它坏了。我看到了它的代码
我还尝试在我的 App.xaml 文件中使用 ResourcesDictionary
<OnPlatform x:TypeArguments="x:String" x:Key="FontAwesome">
<On Platform="iOS" Value="Font Awesome 5 Free" />
<On Platform="Android" Value="fa-regular-400.ttf#Font Awesome 5 Free Regular" />
</OnPlatform>
得到了同样的结果。 可能是什么问题?
最佳答案
我在这里找到了解决方案 https://forums.xamarin.com/discussion/30298/fontfamily-not-working-when-using-textproperty-binding
它将像
这样的字符串更改为像 \uf11a
这样的 unicode 值,它对我有用。简单明了
附注祝大家新年快乐! :)
关于c# - Xamarin.Forms FontAwesome 不适用于绑定(bind)属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53990920/