I’m writing an application which will display the current image seen by a camera and it needs to update the shown image in real time, or close to it. Essentially, I have a camera with which I can capture images and I need to capture one every, say, 1 second and display that image to the screen. Currently, my application has an Image control and I’m capturing a BitmapImage from the camera and setting this as the Image.Source. My trouble is getting this to continuously update. Unfortunately, I have no experience dealing with something like this that has to update itself forever (or until the application I’m writing is closed) and honestly there seems to be very little to none (that I have been able to unearth) on the web about doing something like this in WPF/C#. I suspect I’ll have to spawn a thread to perform the image capturing, but honestly, that’s part of my issue–I have very little experience working with threads and am a bit confused on how all that works. Thanks so much for any help you can provide.
Share
To make the data binding get updated properly, you can use INotifyPropertyChanged. Just add a reference to System.ComponentModel:
Then inherit the interface:
Then add the following code:
Finally, add your property that you want to bind to.
Finally, in your xaml, change the binding to {Binding CurrentImage} and then for the window, set the data context to relative source self… this would be a property for the window:
That should get the binding working properly. Doing things on a separate thread would require the dispatcher