views:

277

answers:

1

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?

alt text

+2  A: 

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"};
Igor Zevaka
Should be CollectionOfFilePaths in code behind, not or ;-)
jeffora
Fat fingers + Cold = One of those real painful Data Binding errors that's not evident until runtime. Thanks for pointing it out.
Igor Zevaka