MBU
MBU

Reputation: 5098

dynamically adding images to a list box in WPF

I have a WPF application that has a vertical listbox that I would like to programmaticly add images to. I want to be able to use a FileSystemWatcher to monitor the directory that the photos are in and when a new image is added or an image is deleted the list box will update the images in the application. Does anyone know how to accomplish this?

Upvotes: 0

Views: 2057

Answers (1)

Dan J
Dan J

Reputation: 16708

Very roughly, you bind the ItemsSource property of the ListBox to an ObservableCollection of images. Have your watcher process add images to the collection as they appear, and databinding should cause the ListBox to be updated as the backing collection changes.

Further: How to: Create and Bind to an ObservableCollection

That's the general concept. Can't get much more specific than that without knowing anything about your code. :) Good luck!

Upvotes: 2

Related Questions