有没有办法水平自定义列表框/列表视图并添加来自具有图像文件路径记录的数据库的项目(图像)?
问问题
3674 次
1 回答
2
当然,只需为列表框定义一个自定义 ItemTemplate 即可显示图像。还覆盖 ItemsPanel 以使其水平。
<ListBox ItemsSource={Binding CollectionOfFilePaths}>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Image Source="{Binding}"/>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox>
然后在代码隐藏中:
ObservableCollection<string> CollectionOfFilePaths{get;set;}
//....
CollectionOfFilePaths= new ObservableCollection<string>{"c:\filepath1.jpg","c:\filepath1.jpg"};
于 2010-05-06T05:34:12.287 回答