Mike
Mike

Reputation:

Silverlight Image in Listbox

I have a listbox with a data template. The problem is that it expects the source to be a string. The string I have is a uri of an image inside the xap file. So it would be uri( xxx, uri.relative) How do I get it to look inside the xap file for the image since I can only use a string value?

ListBox.ItemTemplate  
DataTemplate  
StackPanel Orientation=Horizontal VerticalAlignment=Center

Image Source="{Binding Path=Image}" Width="50" Height="50" Margin="0,0,10,0"  
StackPanel 
DataTemplate  
ListBox.ItemTemplate

//it won't let me use URI for the Image return value!!!

public class MyListboxItem

{

public String Image

{

get { return thumb; 

}

}

Upvotes: 1

Views: 2078

Answers (1)

Mike
Mike

Reputation:

It uses an image source... but it will redily convert a string to an imagesource for you. So i just had to create a bitmap and send that... and create a bitmap in a seedy way.

public ImageSource Image { get {
StreamResourceInfo rs = App.GetResourceStream(new Uri( thumb, UriKind.Relative));

           if (rs == null)
              return new BitmapImage();

           BitmapImage bitmapPreview = new BitmapImage();
           bitmapPreview.SetSource(rs.Stream);
           return bitmapPreview; 
        }
    }

Upvotes: 1

Related Questions