【发布时间】:2021-07-04 05:31:18
【问题描述】:
我还是 Xamarin 表单的新手,现在我正在使用 Ffimagloading 库通过我的视图模型的“DisplayImage”属性显示 gif。但是在满足某些条件后,我想隐藏/卸载图像,使其不再存在。 这是我视图中的 CachedImage:
<ffimage:CachedImage Grid.Column="0"
Source="{Binding DisplayImage}" />
这是我的 ViewModel 中对应的部分:
private ImageSource displayImage;
public void DownloadAndAssignImage() {
try
{
var response = await this.DownloadFile(new Uri("..."));
if (response != null)
{
this.DisplayImage = ImageSource.FromStream(() => new MemoryStream(response));
}
}
catch (Exception e)
{
Log.Error(e);
}
}
public void HideImage()
{
// does not work
this.DisplayImage = null;
// does not work too
this.DisplayImage = new byte[0];
}
public ImageSource DisplayImage
{
get => this.displayImage;
set
{
this.displayImage= value;
this.RaisePropertyChanged();
}
}
我怎样才能做到这一点,以便在通过“DownloadAndAssignImage()”将 ImageSource 分配给 CachedImage 后,它不再显示任何内容?将 ImageSource 设置为 null 或空的 byte[] 数组不起作用。我究竟需要如何修改“HideImage()”方法?
提前感谢您的帮助!
【问题讨论】:
标签: c# xamarin.forms mvvm-light ffimageloading