xaml - TabbedPage 选项卡图标不适用于字体真棒
问题描述
我正在尝试在我的 Xamarin iOS/android 应用程序中将图标添加到我的选项卡中,在我的 Xamarin iOS/android 应用程序中,我查看了许多教程并尝试做同样的事情,但以下代码有问题:
<TabbedPage.Children>
<mypages:List Title="Lista">
<Tab.Icon>
<FontImageSource FontFamily="{StaticResource FontAwesomeSolid}" Glyph="" Size="Small" />
</Tab.Icon>
</mypages:List>
</TabbedPage.Children>
一切正常,直到我添加了这些<Tab.Icon>
东西。
解决方案
你得到的错误是不言自明的:
“在类型‘Tab’中找不到可附加属性‘Icon’”,<Tab.Icon> 下划线。
Icon
type中没有调用属性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 的详细信息:如何在项目中使用 Font Awesome 图标作为 ImageButton 的图标