I want to put images in my ListBox using Binding.
Below is the object containing the URI’s:
_roomView.Room = new Room
{
Items = new List<Item> {
new Item {ItemType = ItemType.BlueKey, ImageUri = "/Escape;component/Images/Items/a.jpg"},
new Item {ItemType = ItemType.Bracelet, ImageUri = "/Escape;component/Images/Items/b.png"},
new Item {ItemType = ItemType.Money, ImageUri = "/Escape;component/Images/Items/b.png"}}
};
DataContext = _roomView;
Below is the XML:
<ListBox x:Name="Mylist">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="5">
<Image Source="{Binding Room.Items.ImageUri}" Stretch="None" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
The images aren’t showing.
Can anyone see where I am going wrong?
If image doesn’t show
– check pathes;
For example my code for binding
If You are using images from the project be sure that thay Build to content and copy always to output directory.(properties of the images )
By the way if you want to show images from the Internet You need to use LowProfileImageLoader
You can read more about it
http://blogs.msdn.com/b/delay/archive/2010/09/02/keep-a-low-profile-lowprofileimageloader-helps-the-windows-phone-7-ui-thread-stay-responsive-by-loading-images-in-the-background.aspx