【发布时间】:2013-07-27 15:47:20
【问题描述】:
问题:
没有显示图像。请帮助纠正我的错误。谢谢
1) 我已将照片存储在名为 Images 的文件夹中,并将照片标记为内容
2) 我已经创建了一个类并添加到项目中
class ModelImage
{
public string Image_Name { get; set; }
public string Image { get; set; }
public string Description { get; set; }
}
3) 我在 MainPage 中添加了 ListView 和一个 Button
<ListView Name="LV" ItemsSource="{Binding}" HorizontalAlignment="Left" Height="552" Margin="693,27,0,0" Grid.Row="1" VerticalAlignment="Top" Width="582">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock FontSize="30" Text="Hello">
<Image Source="{Binding Image}" Height="300" Width="300">
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
--- 按钮
private void Button_Click_1(object sender, RoutedEventArgs e)
{
List <ModelImage> list = new List <ModelImage>();
{
new ModelImage { Image_Name = "Meat", Image = "/Images/Meat_ProkChop.jpg", Description = "Pork Chop" };
new ModelImage { Image_Name = "Meat", Image = "/Images/Meat_Beef.jpg", Description = "Beef" };
};
LV.DataContext = list;
}
我是否需要对名为 Images 的文件夹中的照片使用硬编码路径?
【问题讨论】:
-
首先,我会使用
ObservableCollection而不是List。其次,如果您可以直接访问ListView,只需直接设置其ItemsSource。它可能没有响应DataContext中的更改。 -
不工作,我试过 LV.ItemsSource = list;你有任何示例参考。谢谢
-
标记正确答案被认为是礼貌的。
标签: c# windows-8 windows-store-apps winrt-xaml