嵌入式图像未显示

威利

这是我在便携式项目中的页面

    <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

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文件夹中,但是未显示任何图像。

调试时,我看到返回的imageSource是Xamarin.Forms.StreamImageSource类型。我如何检查是否真的找到了?

有人可以在这里发现错误吗?

威利

正确的XAML是将应用名称添加到源中。

<Image Source="{local:ImageResource MyMobileApp.myimage.jpg}" />

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章