Displaying the StorageItem thumbnail in the converter

In Windows Phone 8.1 Runtime, we can retrieve StorageItem thumbnails asynchronously using the GetThumnailAsync () method.

I am trying to display a list of files in a specific folder with a thumbnail set for each item in the list in the converter.

However, the converter must work synchronously. Anyway, to do this?

+4
source share
1 answer

Instead of running asynchronous code in the converter, let your binding work when the (GetThumbnail) task is complete. Here's a nice post from Stephen Cleary on patterns for asynchronous MVVM - Applications: data binding.

You will find there a class that I think you can use - NotifyTaskCompletion. In the define code:

public NotifyTaskCompletion<BitmapImage> MyThumbnail { get; set; }
// run somewhere your async job:
MyThumbnail = NotifyTaskCompletion<BitmapImage>(file.GetThumnailAsync());

Then in xaml you can use the converter, which will be launched immediately after the task returns the result:

<Image Source="{Binding MyThumbnail.Result}" Visibility="{Binding
  MyThumbnail.IsSuccessfullyCompleted, Converter={StaticResource BooleanToVisibilityConverter}}"/>
+3
source

All Articles