我试图在更改ImageSource时更新/重新绘制图像,这将帮助我重新加载异步。Xamarin.Forms将SetBinding设置为Image,以便在Source更改时刷新
我认为绑定到图像的imageSource具有绑定属性是一个开始,但它不更新图像。我尝试了很多方法,包括使用OnPropertyChanged事件的viewModel方法,但我不认为我完全理解这一点。
此绑定也必须在代码中完成,这就是应用程序如何写入(最小xaml)。
到目前为止,我一般的途径是:
绑定属性
public static readonly BindableProperty ImageFileProperty = BindableProperty.Create("ImageProperty", typeof(string), typeof(CustomImageClass));
public string ImageProperty { get { return (string)GetValue(ImageFileProperty); } set { SetValue(ImageFileProperty, value); } }
里面的CustomImageClass构造:
this.SetBinding(ImageFileProperty, "ImageProperty");
从这里我想在更新ImageSource并更改图像时更改图像。我希望这足够具体,我认为绑定到xaml的所有不同示例都让我感到困惑,因为我需要在代码中执行这些示例。
非常感谢迭戈!没有你的英语解释是好的。 我并没有正确添加BindingContext,因为您已经为我指出了正确的方法。这现在对我来说很好。 另一件需要注意的事情是PropertyBindings没有得到预期的结果 - 当我试图让这段代码最初工作时,我的图像没有正确改变,但是在完全从应用程序中移除测试设备后,图像返回到正常。可能的缓存类型问题。 –