How to load image saved from disk at runtime in a DataGrid

3 posts, 0 answers
  1. Sebastien
    Sebastien avatar
    9 posts
    Member since:
    Oct 2010

    Posted 09 May Link to this post

    Hello,

    For more than a decade, an ImageSource accepts an URL to load an image on the fly. Windows has its own caching system.

    In our app, we have a way to download all the images needed into disk, so if the system is disconnected from the Internet, we could continue to load images.

    Challenge: I haven't found a way to load an image on the fly with the source being an image on disk. One part of the issue is a Converter does not accept async methods.

    Thanks
  2. Nasko
    Admin
    Nasko avatar
    727 posts

    Posted 14 May Link to this post

    Hello Sebastien,

    The DataGrid control itself does not provide an API for loading of images, but only for visualizing them. Basically, there are three approaches that can be used for visualization of images inside the DataGrid:

    1. You can use the built-in DataGridImageColumn. The data passed to the image column should be an ImageSource, string or byte array. If the passed data is a string internally the column creates Uri and pass it as an UriSource to the Image. If the value is byte array a MemoryStream is created and that stream is set as a source for the Image control.

    2. You can create a custom DataGridImageColumn (to inherit from it) and simply to override the PrepareCell method. Inside that method you can manually handle the passed by the ItemsSource value and basically set the Source of the image as desired.

    3. The final approach that could be used is to create a TemplateColumn. Inside the column you can put an Image control and again handle the source manually and as desired.

    Hope the provided information will be helpful for you.

    Regards,
    Nasko
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Sebastien
    Sebastien avatar
    9 posts
    Member since:
    Oct 2010

    Posted 14 May in reply to Nasko Link to this post

    Hello Nasko,

    Thanks for the answers, I appreciate. You have indeed gave 3 good solutions. I will go with #2. If you don't hear me, it means that it has worked :)

    Have a good day
    Sébastien
Back to Top