n.l*_*ell 5 xaml cross-platform xamarin.ios asset-catalog xamarin.forms
这似乎是一件非常容易的事情,理论上它看起来非常简单:
或者至少这是我在任何地方读到的,但我仍然无法让它工作。
我的 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>
Run Code Online (Sandbox Code Playgroud)
我在资产目录上添加了图像:
我正在 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>
Run Code Online (Sandbox Code Playgroud)
还是不行。尝试清理构建文件夹并删除 bin/obj 文件夹,仍然没有。
尝试将资源添加到资源文件夹并从资产目录中删除图像集:
还是没用。
想法?
编辑 2
我将这 3 个图像留在 Resources 文件夹中,并在 XAML 上添加了扩展名 .png 并且它起作用了,仍然很高兴知道它应该如何使用 Asset Catalog 完成。
我们在 iPhone 上的 Xamarin Live Player 上进行测试,结果发现资产目录尚不受支持。(https://twitter.com/praeclarum/status/941775333753217025?s=08)
感谢您的回复!
归档时间: |
|
查看次数: |
2880 次 |
最近记录: |