所以,我开始研究我的第一个Xamarin Forms应用程序,我遇到了一个奇怪的问题 . 我已经关注了所有死线程,教程甚至是关于嵌入图像的官方文章 .

我目前所拥有的:

我有一个PCL Xamarin.Forms应用程序 . 在PCL资源中,我添加了 .png 并通过属性确保了Build Action为"Embedded Resource" . 在Android中,构建操作设置为"AndroidResource",其中,在iOS中,它们设置为"BundleResource",对于Windows,它设置为"Content",如各种文档中所述 .

我正在使用这些图像在我的XAML中显示为图标 . 我有一个 Tabbed Layout ,在XAML中,我调用了这些资源,以及表示页面的正确XAML文件 . 奇怪的是,Android中的图标显示得很好 . 但是,在iOS和Windows中,他们没有 .

我甚至尝试使用此代码剪切以查看加载的嵌入资源:

// NOTE: use for debugging, not in released app code!
var assembly = typeof(MainPage).GetTypeInfo().Assembly;
foreach (var res in assembly.GetManifestResourceNames())
{
    System.Diagnostics.Debug.WriteLine("found resource: " + res);
}

输出是:

[0:] found resource: MyApp.MainPage.xaml

[0:] found resource: MyApp.App.xaml

[0:] found resource: MyApp.images.icon_settings.png

[0:] found resource: MyApp.images.icon_one.png

[0:] found resource: MyApp.images.icon_two.png

[0:] found resource: MyApp.images.icon_download.png

我试过在iOS,Windows和Android上运行它,正在加载相同的资源 .

现在,另一个奇怪的问题 . 如果我将这些图像称为 "MyApp.images.icon_download.png" ,Android构建崩溃说"Resource Not Found" . 但是,Windows构建得很好,但仍然没有Icon图像 .

问题是什么?我甚至尝试删除iOS和Windows中的所有图像(来自VS本身),然后再添加它们 . 但是,同样的问题 . 我甚至清理并重建了整个解决方案,但同样的问题 .

这是我写的XAML:

<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:MyApp"
             x:Class="MyApp.MainPage"
            BackgroundColor="White">
    <NavigationPage Title="One List" Icon="icon_one.png">
        <x:Arguments>
            <local:ListOfOne />
        </x:Arguments>
    </NavigationPage>
    <NavigationPage Title="Two List" Icon="icon_two.png">
        <x:Arguments>
            <local:ListOfTwo />
        </x:Arguments>
    </NavigationPage>
    <local:ApplicationSettingPage Title="Application Settings" Icon="icon_settings.png"/>
</TabbedPage>

现在,有's one more weird thing. If you noticed that there'的另一个 .png 文件,名为 "MyApp.images.icon_download.png" . 我在另一个XAML中将该图像引用为 "Image="icon_download.png" 并将其放在Button上 . 那个在所有平台上加载都很好 .

我真的不知道这里发生了什么 . 真的需要帮助 .