我想使用 Binding 将图像放入我的 ListBox 中。
下面是包含 URI 的对象:
_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;
下面是 XML:
<ListBox x:Name="Mylist">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="5">
<Image Source="{Binding Room.Items.ImageUri}" Stretch="None" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
图像不显示。
谁能看到我哪里出错了?