Search code examples
c#xamarinmvvmcross

Creating an async ValueConverter in MvvmCross


In my application, my ValueConverter is doing some image conversion (like InMemoryImageValueConverter with extra tasks). This takes a while so my GUI freezes for half a second, which is really annoying.

As it is pretty platform specific, I can't do this in my ViewModels. So I would like to use something like an async ValueConverter to perform this operation in background. Is there a possibility?

Otherwise, what would be best practice? My alternative would be to call this code in activity, which would skip the MVVM pattern.


Solution

  • I found Stephen Cleary's answer to this question helpful: Async Implementation of IValueConverter

    In the end I used his excellent AsyncEx library in a Windows-specific Value Converter to do async conversion of a byte array. For Android and iOS I was able to do the async conversion in MVVMCross custom bindings, without needing a Value Converter.

    A little more information can be found in a blog post that I wrote: http://www.sequence.co.uk/blog/infinite-scrolling-using-mvvmcross-and-xamarin/