Silverlight Image Data Binding

Posted by Alexander on Stack Overflow See other posts from Stack Overflow or by Alexander
Published on 2010-05-27T09:31:20Z Indexed on 2010/05/27 9:51 UTC
Read the original article Hit count: 195

Filed under:
|
|

I am new to Silverlight, and have an issue with binding.

I have a class ItemsManager, that has inside its scope another class Item.

class ItemsManager
{
...
 class Item : INotifyPropertyChanged
 {
  ...
  private BitmapImage bitmapSource;
  public BitmapImage BitmapSource
  {
   get { return bitmapSource; }
   set 
   { 
    bitmapSource = value; 
    if(PropertyChanged != null )PropertyChanged("BitmapSource") 
   }
  }            
 }
}

I do the following in code to test binding:

 {
  ItemsManager.Instance.AddItem("123");
  //Items manager started downloading item visual 
  //part (in my case bitmap image png)

  Binding b = new Binding("Source");
  b.Source = ItemsManager.Instance.GetItem("123").BitmapSource;
  b.BindsDirectlyToSource = true;

  Image img = new Image();
  img.SetBinding(Image.SourceProperty, b);
  img.Width = (double)100.0;
  img.Height = (double)100.0;

  LayoutRoot.Children.Add(img);
}

Once image is loaded, image doesn't appear. Though, if I set directly after image has been loaded its source, it displays well.

I also noticed that PropertyChanged("BitmapSource") never fires, because PropertyChanged is null, like Image never binded to it.

I am looking forward to hearing from you!

© Stack Overflow or respective owner

Related posts about Silverlight

Related posts about image