About Image binding

Dec 5, 2011 at 6:26 PM

I am trying to bind a downloaded image to an Image control...

The XAML is the following:

 <Image HorizontalAlignment="Center" VerticalAlignment="Center" Stretch="Fill" Source="{Binding MyImage,UpdateSourceTrigger=PropertyChanged}" Width="100" Height="100"




I have defined the property MyImage as (using the vmprop snippet ):


public System.Windows.Media.ImageSource MyImage

 And the code to download the image and assign to the property:


[] data = request.DownloadData(url);


using (System.IO.MemoryStream ms = new System.IO.MemoryStream(data))



PngBitmapDecoder decoder = new PngBitmapDecoder(ms, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);

MyImage = decoder.Frames[0];



 But the image doesn't show up in the control (and yet the value of MyImage seems to be correct).

I'd appreciate any comments from you about wether I'm missing something or there is a better way to bind dynamic images using Catel's model.

(This was built upon .NET 4.0 , WPF , Catel 2.3)

Thanks in advance



Dec 6, 2011 at 11:47 AM

Try to use the BitmapImage class as property on the view model. It will work much better than using a source.

Dec 6, 2011 at 12:35 PM

Thank you. I'll will try this way...