将图像动态添加到 WPF 中的列表框
我有一个 WPF 应用程序,它有一个垂直列表框,我想以编程方式向其中添加图像。我希望能够使用 FileSystemWatcher 来监视照片所在的目录,并且当添加新图像或删除图像时,列表框将更新应用程序中的图像。有谁知道如何做到这一点?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
非常粗略地说,您将 ListBox 的
ItemsSource
属性绑定到ObservableCollection
图像。让您的观察程序进程在图像出现时将图像添加到集合中,并且数据绑定应导致 ListBox 随着支持集合的更改而更新。此外:如何:创建并绑定到 ObservableCollection
这是一般概念。如果不了解您的代码,就无法获得比这更具体的信息。 :) 祝你好运!
Very roughly, you bind the
ItemsSource
property of the ListBox to anObservableCollection
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!