嵌入式图像未显示 [英] Embedded images not showing
本文介绍了嵌入式图像未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我在便携式项目中的页面
This is my page in portable project
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:b="clr-namespace:Corcav.Behaviors;assembly=Corcav.Behaviors"
xmlns:local="clr-namespace:MyMobileApp;assembly=MyMobileApp"
x:Class="MyMobileApp.MainPage"
x:Name="MainPage">
<Image Source="{local:ImageResource myimage.jpg}" />
这是我在同一便携式项目中的ImageResourceExtension
This is my ImageResourceExtension in same portable project
namespace MyMobileApp
{
[ContentProperty("Source")]
public class ImageResourceExtension : IMarkupExtension
{
public string Source { get; set; }
public object ProvideValue(IServiceProvider serviceProvider)
{
if (Source == null)
return null;
var imageSource = ImageSource.FromResource(Source);
return imageSource;
}
}
}
我试图将myimage.jpg添加为嵌入到项目的根目录和Resources文件夹中,但是没有显示图像.
I have tried to add myimage.jpg as embedded in root of my project and in Resources folder, but no image is shown.
在调试时,我看到返回的imageSource是Xamarin.Forms.StreamImageSource类型.我如何检查是否真的找到了?
While debugging I see that the returned imageSource is of type Xamarin.Forms.StreamImageSource. How do I check if this is really found?
有人可以在这里发现错误吗?
Can anyone spot the error here?
推荐答案
正确的XAML是将应用名称添加到源中.
The correct XAML was to add the app name to the source.
<Image Source="{local:ImageResource MyMobileApp.myimage.jpg}" />
这篇关于嵌入式图像未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文