I'm new to WPF but I've done C# for quite some time now and I am currently developing a simple window (Windows Desktop) that should visualize all photos in a directory. The application should also know about EXIF data like ISO, aperture and so on, for which I use a DLL.
I have defined a Photo
class:
public class Photo {
public string FileName { get; set; }
public int ISO { get; set; }
...
}
that I want to store in a List<Photo>
at runtime.
I've then declared a PhotoItem
(XAML User Control) with an Image control and a TextBlock on it. For every Photo
created there will be one PhotoItem
created that holds the corresponding Photo
as a property:
public partial class PhotoItem : UserControl {
...
public Photo Photo { get; set; }
...
}
From this Photo
property the PhotoItem
knows where to look for the image and what ISO etc. to display.
Now to my problem. Because it would take way too long to load the Image itself as well as the metadata already if the user selects the directory, I want to first add all the PhotoItem
s to the window (still empty) and then run the metadata lookup and Image thumbnail loading for each of them. Of course it would be best if these operations don't block the UI thread, hence I'm currently using one Task
for gathering metadata and one for gathering the thumbnail.
How would I make the PhotoItems update if metadata for the image is now available? Basically how can you have one centralized location where all data is stored, to which Tasks can provide updates and from which the UI thread can build information. I know a bit about Bindings in XAML/WPF, but binding e.g. a TextBlock's text to the Photo.ISO
variable would always display zero if the metadata was not gathered yet. In this case I would want to hide all the text detail on the PhotoItem
.
On the other hand I've also thought about implementing something like a 'Refresh' function inside the PhotoItem
, but that would reload the image and would take a long time (this was probably my favorite WinForms way to do it, haha).
Can anyone give me an idea of how to realize this?
Thanks in advance!
See Question&Answers more detail:os