TabbedPage 选项卡图标不适用于字体真棒

问题描述

我正在尝试使用很棒的字体将图标添加到我的选项卡中,在我的 Xamarin iOS/android 应用程序中,我查看了许多教程并尝试执行相同的操作,但以下代码有问题:

<TabbedPage.Children>

       <mypages:List Title="Lista">
           <Tab.Icon>
               <FontimageSource FontFamily="{StaticResource FontAwesomeSolid}" Glyph="&#xf2bb;" Size="Small" />
           </Tab.Icon>
       </mypages:List>

</TabbedPage.Children>

一切正常,直到我添加<Tab.Icon> 东西。

解决方法

你得到的错误是不言自明的:

“在'Tab'类型中找不到可附加属性“Icon””,带有下划线。

在类型 Icon 中没有名为 Tab 的属性,您可以在下面使用,但正如您所见,它是 IconImageSource 需要提供资源图像名称而不是字体字形。

<TabbedPage.Children>
        <apptest:Page2 IconImageSource="imageName.png"/>
</TabbedPage.Children>

使用字体图标的另一种方法是使用 Shell 来构建标签,而不是使用 TabbedPage,后者通过 FontImageSource 提供字体图标支持:

<Shell>
...
<Tab Title="title">
   <Tab.Icon>
         <FontImageSource FontFamily="FontAwesome" Glyph="{x:Static fonts:IconFont.AddressBook}"/>
   </Tab.Icon>
            <ShellContent ContentTemplate="{DataTemplate local:Page1}"/>
</Tab>

有关 xamarin.forms 中 fontawesome 的详细信息:How to use Font Awesome icons in project as an icon of ImageButton