WPF - Binding to Image Control
Overtime, I have used different approaches to binding pictures to Image control in a WPF application. I have seen various questions on the WPF forum as well on this topic. The information is all available out there, but scattered. Hence, I decided to create a sample application to demostrate the various scenarios that can exist when you need to use the Image control to display pictures.
You can download the demo code (Download file) and play around with it. If you unzip it in C:\, it should work without having to change any file paths etc. There are 7 scenarios that i have currently handled in code. If you can think of more, do pass them along and I will update the code to add them as well
- Regular resource image binding to Source property in XAML
- Binding resource image, but from code behind
- Binding resource image in code behind by using Application.GetResourceStream
- Loading image from file path via memory stream (same is applicable when loading blog image data from database)
- Loading image from file path, but by using binding to a file path Property
- Binding image data to a user control which internally has image control via dependency property
- Same as point 5, but also ensuring that the file doesn't get's locked on hard-disk
Comments welcome !