- For individual users
- Instant access to solutions
- Ask your tech questions
- Start your 30-day Free Trial
Main Topics
Browse All TopicsUsing WPF, C# - binding an object to a WPF ListBox with a DataTemplate.
The goal is to declaratively bind an ObservableCollection class to a WPF ListBox. The LIstBox should display a collection of Images (PNG Files). The ObservableCollection class picks up image files via a FileWatcher and has a FUlLPath public property that is used to bind the SOURCE property of an IMAGE element.
However, the ListBox will not render the images. WHen I debug, the ObservableCollection class DOES populate with items, and I can access the FullPath property.
I found out via MSDN that to make my ObservableCOllection class get recognized in XAML, I had to add a namesspace in my Widnow declaration.
xmlns:src="clr-namespace:W
and also a Resource for the class.
<Window.Resources>
<src:FishBooks x:Key="FishBooks"/>
...
because prior the ListBox
<ListBox ItemsSource="{Binding Source={StaticResource FishBooks}}
was getting a compile error :FishBooks...not found..."
But I still am not able to get the ListBox to render the class Collection items.
All COde is pasted below.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: unmeshdavePosted on 2009-07-21 at 23:51:26ID: 24912050
regarding the collection, I already gave reply to
http://www.experts-exchang e.com/Micr osoft/Deve lopment/Mi crosoft_Pr ogramming/ WPF_and_Si lverlight/ Q_24586234 .html#a249 11984
and to get images in listbox you can replace textblock in datatemplate with following
<Image Source="{Binding Path=FullPath}" Height="35" Grid.Row="0" />
Select allOpen in new window