来自Xamarin.Forms资源的图像有时不显示

时间:2016-07-13 12:33:05

标签: xamarin xamarin.forms

某些时候来自Xamarin.Forms资源的图片不显示并显示为黑色矩形。

无论如何都要阻止它吗?

<Image Source="{ex:ImageResource MyProjects.Images.Data.png}"
           Aspect="AspectFit"
           AbsoluteLayout.LayoutBounds="0.15,0.15,0.7,0.7"
           AbsoluteLayout.LayoutFlags="All" >
</Image>


[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;
  }
}

0 个答案:

没有答案