【发布时间】:2019-03-18 12:53:09
【问题描述】:
我正在尝试在共享项目资源中显示和嵌入图像(如 Microsoft 文档中的 here 所述)。
我创建了 ImageResourceExtension,项目可以编译,但是启动项目时出现以下错误:
无法从 程序集'Xamarin.Forms.Core,版本=2.0.0.0
这是我的代码:
MainPage.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:App1"
x:Class="App1.MainPage">
<StackLayout>
<Image x:Name="imgTest" Source="{local:ImageResource img.jpg}" />
</StackLayout>
</ContentPage>
EmbeddedImage.cs
namespace App1
{
[ContentProperty(nameof(Source))]
public class ImageResourceExtension : IMarkupExtension
{
public string Source { get; set; }
public object ProvideValue(IServiceProvider serviceProvider)
{
if (Source == null)
return null;
// Do your translation lookup here, using whatever method you require
var imageSource = ImageSource.FromResource(Source, typeof(ImageResourceExtension).GetTypeInfo().Assembly);
return imageSource;
}
}
}
【问题讨论】:
-
你能提供你的代码吗?您确定问题与图像有关吗?
-
如果我删除
我没有得到错误。所以很确定它是相关的:) 我将代码添加到我的初始帖子中。谢谢 -
你能提供你的图片的路径吗?您的图片保存在共享项目中的什么位置?
标签: xamarin xamarin.forms