This is a migrated thread and some comments may be shown as answers.

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

2 Answers 77 Views
DataGrid
This is a migrated thread and some comments may be shown as answers.
Sébastien
Top achievements
Rank 2
Iron
Iron
Iron
Sébastien asked on 10 May 2019, 02:21 AM
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 Answers, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 14 May 2019, 08:51 AM
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
0
Sébastien
Top achievements
Rank 2
Iron
Iron
Iron
answered on 14 May 2019, 11:56 AM
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
Tags
DataGrid
Asked by
Sébastien
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Nasko
Telerik team
Sébastien
Top achievements
Rank 2
Iron
Iron
Iron
Share this question
or