【发布时间】:2023-04-07 15:02:02
【问题描述】:
我正在使用以下代码 sn-p 将图像 url 绑定到图像对象(用作 ViewCell 对象中的一个元素)。
...
Image Picture = new Image()
{
Aspect = Aspect.AspectFit,
HorizontalOptions = LayoutOptions.StartAndExpand
}; // ImageSource.FromUri(new Uri("sImageUrl")))
Picture.SetBinding(Image.SourceProperty, "sImageUrl");
...
列表中的图像(我正在使用该单元格视图)并不总是加载。我无法确定问题的确切原因,但我认为问题在于加载过程(用于从 url/internet 加载图像)..
也许问题可以通过按照文档中的描述通过 new Uri(...) 设置 url 来解决
var webImage = new Image { Aspect = Aspect.AspectFit };
webImage.Source = ImageSource.FromUri(new Uri("https://xamarin.com/content/images/pages/forms/example-app.png"));
现在我的问题是:是否有绑定 uri 对象的解决方法?例如
...
Image Picture = new Image()
{
Aspect = Aspect.AspectFit,
HorizontalOptions = LayoutOptions.StartAndExpand
}; // ImageSource.FromUri(new Uri("sImageUrl")))
Picture.SetBinding(Image.SourceProperty, ImageSource.FromUri(new Uri("sImageUrl")));
...
我正在使用 xamarin studio(版本 6.1.2,内部版本 44,更新频道“beta”,os x)。
如果有人给小费就好了。
非常感谢,
亚历克斯
【问题讨论】:
-
为什么 ImageSource.FromUri 对您不起作用,如文档中所述?
-
嗨,一旦我尝试绑定“uri”值,我就会收到消息:错误 CS1929:类型
Xamarin.Forms.Image' does not contain a memberSetBinding' 和最佳扩展方法重载Xamarin.Forms.TemplateExtensions.SetBinding(this Xamarin.Forms.DataTemplate, Xamarin.Forms.BindableProperty, string)' requires an instance of typeXamarin.Forms .DataTemplate' (CS1929)