我有一个主从页面,我想将导航栏中的图标设置为菜单。因此,我将我的图片放入资产目录(资产目录 > 媒体 > 菜单)。如果我想从XAML引用该图片,则当图片在资产目录中时不会显示出来。
我尝试了不同的路径,但它们都无法正常工作。调试也不显示任何图片。似乎Xamarin.Forms不支持资产目录,但这是不正确的。在普通内容页面上,我有以下内容:
这个工作没有问题。在我的
基本上,这是相同的代码,但图标不显示。只有将图像放入“资源”文件夹中才能显示图标...但我如何在我的XAML中使用来自资产目录的图像?
我尝试了不同的路径,但它们都无法正常工作。调试也不显示任何图片。似乎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>
基本上,这是相同的代码,但图标不显示。只有将图像放入“资源”文件夹中才能显示图标...但我如何在我的XAML中使用来自资产目录的图像?