title: xamarin.forms bind listview-imagecell imagesource to byte[]
body: <p>I'm currently getting started with Xamarin.Forms. I have a ListView on my page, that I bind to my ViewModel. The ItemTemplate is of the type 'ImageCell'</p>
  
  <p>There's no problem with binding the Text and Detail properties of the cell. However, I can't manage to bind the 'ImageSourceProperty'. This is imagesource is generated using a byte[] (My images are blobs in a SQLite database)</p>
  
  <p>I was wondering if anyone knew how to solve this problem (or another way to bind a byte[]-image to a listview-item)</p>
  
  <p>Here's some sourcecode:</p>
  
  <pre><code>var model = Graanziekten.Select(g =&gt; new OnkruidViewModel
              {
                  Id = g.Id, Naam = g.Naam, Omschrijving = g.Omschrijving, Afbeelding = g.BitmapThumbnail
              }).ToList();
  
              var cell = new DataTemplate(typeof(ImageCell));
              cell.SetBinding(TextCell.TextProperty, "Naam");
              cell.SetBinding(TextCell.DetailProperty, "Omschrijving");
              cell.SetBinding(ImageCell.ImageSourceProperty, "Afbeelding");
  
              var listview = new ListView
              {
                  ItemsSource = model,
                  ItemTemplate = cell
              };
  </code></pre>
  
  <p>the 'BitmapThumbnail' property is defined as:</p>
  
  <pre><code>public ImageSource BitmapThumbnail
          {
              get
              {
                  //AfbeeldingSmall is a byte[]
                  return ImageSource.FromStream(() =&gt; new MemoryStream(Afbeeldingen.First().AfbeeldingSmall));
              }
          }
  </code></pre>
  
  <p>If I use a dummy image (from a uri) it works fine. But if I use the code shown above, the contentpage isn't even rendered at all (empty black screen).</p>
  
  <p>At first I thought the problem might have something to do with the fact the byte[] is fetched from the property dynamically, but the same effect occurs when I fetch all the necessary byte[]'s.</p>
  
  <p>Also, when I add a single image to my contentpage, using the same method it DOES work. Just not in the listview.</p>
  
  <p>I'm trying to do this on WinPhone8 (Although I don't think the platform matters)</p>
  
  <p>Thanks in advance.</p>