使用"伺机"在转换器(的IValueConverter)不工作? [英] Using "await" in a converter (IValueConverter) not working?

查看:211
本文介绍了使用"伺机"在转换器(的IValueConverter)不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个转换器在我的Windows Phone应用程序,但似乎你不能使用它等待的方法?

I have a converter in my Windows Phone application but it seems you cannot use "await" methods in it?

public object Convert(object value, Type targetType, object parameter, string language)
{
    _IDataService = ServiceLocator.Current.GetInstance<IDataService>();

    string imageUrlId = (string)value;

    byte[] imageByte = await iDataService.GetImage(imageUrlId);

    return LoadImageAsync(imageByte);
}

如果我让异步任务的方法,它说的IValueConverter没有方法任务异步。该转换器返回一个类型的ImageSource。

If I make the method async Task it says IValueConverter has no method Task async. This converter returns type ImageSource.

推荐答案

您不能因为你必须为接口的IValueConverter的所有方法提供实现改变转换方法的签名。

You can't change the signature of the Convert method since you have to provide an implementation for all the methods of the IValueConverter interface.

我最常做的视图模型的图像加载异步从后端,而不是在UI线程。有了正确的绑定,该图像将在你的用户界面,只要它被加载显示。

What I usually do is loading in the images of the view-model asynchronously from the backend, not on the UI thread. With the proper bindings, the images will be displayed on your UI as soon as it is loaded.

这篇关于使用&QUOT;伺机&QUOT;在转换器(的IValueConverter)不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆