Xamarin.Forms:使用来自资源目录的图像

5
我有一个主从页面,我想将导航栏中的图标设置为菜单。因此,我将我的图片放入资产目录(资产目录 > 媒体 > 菜单)。如果我想从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中使用来自资产目录的图像?
1个回答

2
我收到的来自Xamarin的唯一回复是,FileImageSource不能与资源目录一起使用。虽然这并不完全正确,但由于它不是每次都能正常工作,因此不应该使用它。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接