简体   繁体   中英

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.

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM