views:

2445

answers:

2

Suppose I have string Name and Image Photo as properties of a class in my DataContext. I need to bind them to controls is a DataTemplate.

I thought this would work but it doesn't:

<Image Source="{Binding Photo}"/>

Why not? Should I my Photo have another type? (BitmapImage perhaps?)

How can I bind an Image control to an Image property?

Thanks!

Edit: As usual, after clicking submit I saw that the error is very clear: there's no converter from Image to ImageSource. How would my converter be to convert Image to ImageSource?

+1  A: 

Yes, if I make my property BitmapImage it all works just fine. Sorry for the stupid question.

Gustavo Cavalcanti
There are no stupid questions! :) Hope it solved your problem!
Arcturus
+2  A: 

It doesn't really makes sense to have a data property of type Image, since Image is a control (if you really want to do that you could bind to Photo.Source). You should use an ImageSource instead (or a BitmapImage, like you did, since BitmapImage inherits from ImageSource).

Thomas Levesque
I agree Thomas. I started with type Image because for no good reason. :) It wasn't a good idea at all.
Gustavo Cavalcanti