Xamarin.Forms: 使用资产目录中的图像
Xamarin.Forms: Use image from asset catalog
我有一个Master Detail page,我想在导航栏中设置图标来显示菜单。因此,我将图像放入资产目录(资产目录 > 媒体 > 菜单)。如果我想从 XAML 引用该图像,当图像在资产目录中时它不会显示。
我尝试了不同的路径,但都不行。 Debugging 也没有显示任何图像。 Xamarin.Forms 似乎不支持资产目录,但事实并非如此。在正常的内容页面上,我有这个:
<ContentPage.ToolbarItems>
<ToolbarItem Text="Configuration" Activated="OpenConfiguration" Order="Primary" Priority="0">
<ToolbarItem.Icon>
<OnPlatform x:TypeArguments="FileImageSource">
<OnPlatform.iOS>gear.png</OnPlatform.iOS>
<OnPlatform.Android>gear.xml</OnPlatform.Android>
<OnPlatform.WinPhone>Assets/gear.png</OnPlatform.WinPhone>
</OnPlatform>
</ToolbarItem.Icon>
</ToolbarItem>
</ContentPage.ToolbarItems>
这没有问题。在我的 MasterPage
(页面,负责在主细节模板中显示菜单条目)我有这个:
<ContentPage.Icon>
<OnPlatform x:TypeArguments="FileImageSource">
<OnPlatform.iOS>menu.png</OnPlatform.iOS>
<OnPlatform.Android>menu.xml</OnPlatform.Android>
<OnPlatform.WinPhone>Assets/menu.png</OnPlatform.WinPhone>
</OnPlatform>
</ContentPage.Icon>
基本上是相同的代码,只是图标没有显示出来。如果我将图像放入 Resources
文件夹中,我只会显示图标 ...
但是如何在我的 XAML 中使用资产目录中的图像?
我从 Xamarin 得到的唯一回应是,FileImageSource
不能与资产目录一起使用。这并不完全正确,但由于它并非每次都不应该使用它。
我有一个Master Detail page,我想在导航栏中设置图标来显示菜单。因此,我将图像放入资产目录(资产目录 > 媒体 > 菜单)。如果我想从 XAML 引用该图像,当图像在资产目录中时它不会显示。
我尝试了不同的路径,但都不行。 Debugging 也没有显示任何图像。 Xamarin.Forms 似乎不支持资产目录,但事实并非如此。在正常的内容页面上,我有这个:
<ContentPage.ToolbarItems>
<ToolbarItem Text="Configuration" Activated="OpenConfiguration" Order="Primary" Priority="0">
<ToolbarItem.Icon>
<OnPlatform x:TypeArguments="FileImageSource">
<OnPlatform.iOS>gear.png</OnPlatform.iOS>
<OnPlatform.Android>gear.xml</OnPlatform.Android>
<OnPlatform.WinPhone>Assets/gear.png</OnPlatform.WinPhone>
</OnPlatform>
</ToolbarItem.Icon>
</ToolbarItem>
</ContentPage.ToolbarItems>
这没有问题。在我的 MasterPage
(页面,负责在主细节模板中显示菜单条目)我有这个:
<ContentPage.Icon>
<OnPlatform x:TypeArguments="FileImageSource">
<OnPlatform.iOS>menu.png</OnPlatform.iOS>
<OnPlatform.Android>menu.xml</OnPlatform.Android>
<OnPlatform.WinPhone>Assets/menu.png</OnPlatform.WinPhone>
</OnPlatform>
</ContentPage.Icon>
基本上是相同的代码,只是图标没有显示出来。如果我将图像放入 Resources
文件夹中,我只会显示图标 ...
但是如何在我的 XAML 中使用资产目录中的图像?
我从 Xamarin 得到的唯一回应是,FileImageSource
不能与资产目录一起使用。这并不完全正确,但由于它并非每次都不应该使用它。