locked
Image converter and async / UI thread RRS feed

  • Question

  • I have an image converter in my windows 8 store app that is doing a bunch of work and blocking the UI thread. there seems to be no "IsAsync" option like in wpf (I think).   any suggestions for how to implement an image converter that is going to do real work without blocking the UI thread?

    I'm of course talking about this type of thing

      <common:ImageSourceConverter x:Key="ImageSourceConverter" />
    
      <Image x:Name="PictureItemBottom"  
                                   Height="150" Width="150"  
                                   Source="{Binding  ImageFullUrl, Converter={StaticResource ImageSourceConverter},ConverterParameter=150-150}" Grid.ColumnSpan="2" Margin="0,5" />
               
    
    


    Peter Kellner http://peterkellner.net Microsoft MVP • ASPInsider

    Monday, December 3, 2012 10:39 PM

Answers

  • maybe do the work in the ViewModel? dont think you can make a ValueConverter async in Store apps

    so make a property in your viewmodel that is of the right type and alrady do the convert work there.


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#


    Monday, December 3, 2012 11:03 PM
  • Under the assumption of your present binding signature, Dave's view model approach is the best option.

    There is an alternative solution:

    - you declare the converter path as a property MyBusinessObject.MySelf [which contains 'this']
    - if the image exists, the converter returns the image
    - if the image does not exist, the converter performs all image processing on the non-ui thread in an async fashion; it returns null since the image is not yet loaded
    - when the image is loaded, the completion handler sets the MyBusinessObject.Image property. The latter sets the image field value _and_ performs a property notification on behalf of MyBusinessObject.MySelf
    Tuesday, December 4, 2012 7:10 AM

All replies

  • maybe do the work in the ViewModel? dont think you can make a ValueConverter async in Store apps

    so make a property in your viewmodel that is of the right type and alrady do the convert work there.


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#


    Monday, December 3, 2012 11:03 PM
  • Can someone confirm that?

    Peter Kellner http://peterkellner.net Microsoft MVP • ASPInsider

    Monday, December 3, 2012 11:08 PM
  • Under the assumption of your present binding signature, Dave's view model approach is the best option.

    There is an alternative solution:

    - you declare the converter path as a property MyBusinessObject.MySelf [which contains 'this']
    - if the image exists, the converter returns the image
    - if the image does not exist, the converter performs all image processing on the non-ui thread in an async fashion; it returns null since the image is not yet loaded
    - when the image is loaded, the completion handler sets the MyBusinessObject.Image property. The latter sets the image field value _and_ performs a property notification on behalf of MyBusinessObject.MySelf
    Tuesday, December 4, 2012 7:10 AM