WPF/C#: How to add images from a horizontal listbox/listview by (file paths coming from a database table)
Is there are way to customize the listbox/listview开发者_如何学运维 horizontally and add items (images) coming from a database which has a record of image file paths?
Sure, just define a custom ItemTemplate for the listbox to show the image. Also override ItemsPanel to make it horizontal.
<ListBox ItemsSource={Binding CollectionOfFilePaths}>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Image Source="{Binding}"/>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox>
Then in codebehind:
ObservableCollection<string> CollectionOfFilePaths{get;set;}
//....
CollectionOfFilePaths= new ObservableCollection<string>{"c:\filepath1.jpg","c:\filepath1.jpg"};
精彩评论