这似乎是一件非常容易做的事情,而且理论上它看起来非常简单:
- 创建资产目录
- 添加图像集并将其命名为“imageName”(不带 .png)
- 添加图像
- done
或者至少这是我到处读到的内容,但我仍然无法让它发挥作用。
我的 XAML 看起来像这样:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:CrossBaiscs"
x:Class="CrossBaiscs.MainPage">
<ContentPage.Content>
<StackLayout BackgroundColor="Orange">
<Label Text="Welcome to Xamarin.Forms!"
TextColor="White"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" />
<Image VerticalOptions="CenterAndExpand"
HorizontalOptions="Center"
Source="logo1.png"/>
</StackLayout>
</ContentPage.Content>
</ContentPage>
我在资产目录中添加了图像:
我正在 Iphone 6 上使用 Xamarin Live Player 进行测试,但在标签下看不到任何图像。
那么...我错过了什么?
EDIT
它适用于这个人:是否可以在 Xamarin Forms 中使用图像集 https://stackoverflow.com/questions/36796571/is-it-possible-to-use-image-set-in-a-xamarin-forms
但不适合我,我确实尝试删除 .png 扩展名并保留 xaml,如下所示:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:CrossBaiscs"
x:Class="CrossBaiscs.MainPage">
<ContentPage.Content>
<StackLayout BackgroundColor="Orange">
<Label Text="Welcome to Xamarin.Forms!"
TextColor="White"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" />
<Image VerticalOptions="CenterAndExpand"
HorizontalOptions="Center"
Source="logo1"/>
</StackLayout>
</ContentPage.Content>
</ContentPage>
还是不行。
尝试清理构建文件夹并删除 bin/obj 文件夹,仍然没有任何结果。
尝试将资源添加到资源文件夹并从资产目录中删除图像集:
还是没用。
Ideas?
EDIT 2
我将这 3 个图像留在了 Resources 文件夹中,并在 XAML 上添加了扩展名 .png,它起作用了,但如果知道如何使用资产目录来完成它,那就太好了。