开发者

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?

WPF/C#: How to add images from a horizontal listbox/listview by (file paths coming from a database table)


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"};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜