【发布时间】:2020-02-04 23:34:28
【问题描述】:
我想更改位于 TabbedPage 的 ToolbarItem 中的几个图标,我查看了文档 here,我要么错过了重点,要么我希望实现的目标不可行?
我目前正在使用 FontAwesomeIcons 在我的应用程序中填充图标,从静态的角度来看,它们效果很好。但在某些情况下,我可能希望更改图标、颜色或图标包(例如 Light to Solid)。
App.xaml - 我用它来引用我的 .otf 文件
<Application.Resources>
<OnPlatform x:Key="FontAwesomeProLight" x:TypeArguments="x:String">
<On Platform="iOS" Value="FontAwesome5Pro-Light" />
</OnPlatform>
<OnPlatform x:Key="FontAwesomeProSolid" x:TypeArguments="x:String">
<On Platform="iOS" Value="FontAwesome5Pro-Solid" />
</OnPlatform>
</Application.Resources>
ExamplePage.xaml - 这将是我当前(非动态)显示我的图标的页面
<TabbedPage.ToolbarItems>
<ToolbarItem Clicked="OnFilterOrders">
<ToolbarItem.IconImageSource>
<FontImageSource FontFamily="{StaticResource FontAwesomeProLight}" Glyph="{x:Static fonts:FontAwesomeIcons.Filter}" />
</ToolbarItem.IconImageSource>
</ToolbarItem>
</TabbedPage.ToolbarItems>
所以此时的代码完美地显示了一个静态图标,下面是我失败的尝试 - 但没有抛出错误,我只是得到一个 ?而是
ExamplePage.xaml
<TabbedPage.ToolbarItems>
<ToolbarItem Clicked="OnFilterOrders">
<ToolbarItem.IconImageSource>
<FontImageSource FontFamily="{DynamicResource FontAwesomeIconPack}" Glyph="{x:Static fonts:FontAwesomeIcons.Filter}" />
</ToolbarItem.IconImageSource>
</ToolbarItem>
</TabbedPage.ToolbarItems>
使用该页面的代码隐藏,我在构造函数中也有以下内容。
Resources["FontAwesomeIconPack"] = App.Current.Resources["FontAwesomeProLight"];
我是否正确假设 Resources["FontAwesomeIconPack"] 与页面资源字典链接,而 App.Current.Resources["FontAwesomeProLight"] 与 app.xaml 页面链接?
我希望在这个示例中能够显示我现有的图标,但事实并非如此。我的期望是和以前一样的图标(在我换包之前),但我只是得到一个?)。
【问题讨论】:
标签: c# xaml xamarin xamarin.forms