从ViewModel类调用FFImageLoading的GetImageAsPngAsync?

时间:2017-11-24 17:01:31

标签: xamarin.forms ffimageloading

https://github.com/luberda-molinet/FFImageLoading用于Xamarin表单

我的XAML:

 <forms:CachedImage
CacheType="All"
RetryDelay="1000"
DownsampleHeight="150"
RetryCount="5"
CacheDuration="1"
BackgroundColor="WhiteSmoke"
BitmapOptimizations="True"
SuccessCommand="{Binding CcCommand}"
Source = "{Binding Photo1}">

我的ViewModel类:

class AboutMeViewModel : INotifyPropertyChanged
{
    public ICommand CcCommand { get; set; }

    public AboutMeViewModel()
    {
        CcCommand = new Command<CachedImageEvents.SuccessEventArgs>(ffFinishLoading);
    }

    void ffFinishLoading(CachedImageEvents.SuccessEventArgs ea)
    {
       // Here I would like to call 'GetImageAsPngAsync'
    }

    public event PropertyChangedEventHandler PropertyChanged;
    protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
}

在ffFinishLoading我想调用GetImageAsPngAsync,但我找不到在ViewModel类中执行此操作的方法,因为我没有选择参考表单:从XAML文件到ViewModel文件的CachedImage。

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:2)

var stream = await ImageService.Instance.LoadUrl(Photo1).AsPNGStreamAsync();