【发布时间】:2018-05-25 11:14:40
【问题描述】:
这似乎是一件很容易做到的事情,理论上它看起来非常简单:
- 创建资产目录
- 添加一个图像集并将其命名为“imageName”(不带 .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.png"/>
</StackLayout>
</ContentPage.Content>
</ContentPage>
我在资产目录中添加了图片:
我正在 Iphone 6 上使用 Xamarin Live Player 进行测试,但在标签下看不到任何图像。
那么...我错过了什么?
编辑
它适用于这个人: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 文件夹,仍然没有。
尝试将资源添加到资源文件夹并从资产目录中删除图像集:
还是不行。
想法?
编辑 2
我将这 3 张图片留在了 Resources 文件夹中,并在 XAML 上添加了扩展名 .png 并且它工作正常,仍然很高兴知道它应该如何使用资产目录来完成。
【问题讨论】:
-
它在我这边工作正常,尝试将名为 logo1.png 的图像直接添加到
Resources文件夹,看看它是否可以工作。
标签: xaml xamarin.ios xamarin.forms cross-platform asset-catalog