【问题标题】:TabbedPage tab icons not working with font awesomeTabbedPage 选项卡图标不适用于字体真棒
【发布时间】:2021-05-20 19:41:23
【问题描述】:

我正在尝试在我的 Xamarin iOS/android 应用程序中将图标添加到我的标签中,在我的 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>

在我添加 &lt;Tab.Icon&gt; Stuff 之前一切正常。

【问题讨论】:

  • 你能准确地说出什么不工作吗?
  • 好吧,当我编译代码时,我收到一条错误消息:“在类型‘Tab’中找不到可附加属性‘Icon’”, 下划线。
  • 但是图标在标签和东西中起作用
  • TabbedPage 工作正常,唯一不工作的部分是图标部分

标签: xaml xamarin xamarin.forms tabbedpage


【解决方案1】:

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

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

Tab 类型中没有名为 Icon 的属性,您可以在下面使用,但如您所见,它是 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

【讨论】:

  • 我如何将现有的 XAML 连接到该选项卡?同样的方式?
  • 正如您可能在 Shell 文档中一样,它是一种不同的语法/层次结构,您可能需要花费一些时间(或多或少取决于您的应用程序大小)来迁移到 Shell。 Shell.Tabs
猜你喜欢
  • 2021-03-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-16
相关资源
最近更新 更多