【问题标题】:Xamarin.Forms FontAwesome doesn't work with bound propertiesXamarin.Forms FontAwesome 不适用于绑定属性
【发布时间】:2018-12-31 19:42:43
【问题描述】:

我想在我的 Xamarin.Forms 项目中添加很棒的字体,并且我已将它添加到项目中。 然后我将 FontFamily 添加到这样的标签中:

<ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <Grid Padding="15">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="9*" />
                            </Grid.ColumnDefinitions>
                            <Label Grid.Column="0" Text="&#xf11a;" 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>

这段代码运行良好,结果是

但是当我将这些硬编码的东西更改为这样的可绑定属性时:

<Label Grid.Column="0" Text="{Binding FontAwesomeIconText}" FontSize="20">

在c#中这样设置

menuItems = new List<DrawerMenuItem>
            {
                new DrawerMenuItem {Id = MenuItemType.Browse, Title="Browse", FontAwesomeIconText = "&#xf11a;" },
                new DrawerMenuItem {Id = MenuItemType.About, Title="About" , FontAwesomeIconText = "&#xf11a;"}
            };

它坏了。我看到了它的代码

我还尝试在我的 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>

得到了同样的结果。 可能是什么问题?

【问题讨论】:

    标签: c# font-awesome-5 xamarin.forms.listview


    【解决方案1】:

    我在这里找到了解决方案https://forums.xamarin.com/discussion/30298/fontfamily-not-working-when-using-textproperty-binding

    它将&amp;#xf11a; 之类的字符串更改为\uf11a 之类的unicode 值,它对我有用。简单明了

    附言祝大家新年快乐! :)

    【讨论】:

    猜你喜欢
    • 2020-11-19
    • 1970-01-01
    • 1970-01-01
    • 2017-03-04
    • 2018-03-24
    • 2019-12-04
    • 2016-06-06
    • 2020-01-02
    相关资源
    最近更新 更多