The main problem is that you need to perform the async operation in a synchronous operation ( Convert ). This is not an easy way to do this; if possible, structure your code so that it is not necessary (for example, one property starts updating async another property, which is the result of the "conversion").
If you want to try to make it fit, you should use ConfigureAwait(false) :
public object Convert(object value, Type targetType, object parameter, string language) { // Note that "Result" will wrap any errors in AggregateException, which is annoying. return IfFileExist((string)value, "localimage.png").Result; } public async Task<string> IfFileExist(string value, string filename) { var folder = ApplicationData.Current.LocalFolder; var getFilesAsync = await folder.GetFilesAsync(CommonFileQuery.OrderByName) .AsTask().ConfigureAwait(false); var file = getFilesAsync.FirstOrDefault(x => x.Name == filename); if (file != null) { return "ms-appdata:///local/" + filename; } return (string)value; }
source share