0

I'm trying to add a dynamic Image in my WPF form. I've added the Image like this:

<Image Height="212" HorizontalAlignment="Left" Margin="12,167,0,0" 
   Name="picture_scan" Stretch="Fill" VerticalAlignment="Top" Width="227" 
   Source="{Binding FingerprintSource}" />

The source leads to the following code in my service class:

public BitmapSource FingerprintSource
{
    get { return fingerprintScan.WpfImageSource; }
}

The WpfImageSource is a BitmapSource. As I said, the Image is dynamic. Through an event from my Fingerprint Reader, the following code is called:

private void HandleFingerprintObtainedEvent(Fingerprint fingerprint, FingerprintImage fingerprintImage)
{
    Debug.WriteLine("New fingerprint found!");
    fingerprintScan = fingerprintImage;
}

When I run the program and press my finger on the reader, a new fingerprint image is found. The value fingerprintScan is being changed. But the problem is, before and after putting my finger on the scanner, the bitmap is empty (white?). What am I doing wrong? Do I need to do more besides databinding, like checking for events or something? Is it a problem when the source of the databinding is a BitmapSource instead of a BitmapImage?

Joetjah
  • 6,292
  • 8
  • 55
  • 90

1 Answers1

1

You are not notifying that the property has changed.

The class that has de FingerprintSource property has to implement the interface INotifyPropertyChanged. Then you can use the property setter to raise the PropertyChanged event. Otherwise the WPF binding does not know that something has changed.

Here you have a good start point: WPF/MVVM Quick Start Tutorial

JoanComasFdz
  • 2,911
  • 5
  • 34
  • 50
  • Ok, so I've tried the code from the example and my `RaisePropertyChanged` is being fired when I insert a new image. How do I let the WPF binding know it's the Fingerprintscan that's changed, and refresh the Image on the WPF accordingly? – Joetjah Feb 26 '13 at 11:42
  • First, make sure your WPF window/page has the DataContext set correctly. As soon as you fire the event, the binding receives it and will automatically update the value (in this case an image). If this is not happening, take a look at the Output window to see any binding problems. – JoanComasFdz Feb 26 '13 at 11:46
  • The DataContext is set correctly. I'm using other values for ComboBoxes and ListViews. The event gets triggered as well when I press my finger on the scanner, and the image is being refreshed (replaced). But then, my picture isn't refreshed. Perhaps the error is in the `RaisePropertyChanged("fingerprintScan");`? What String-value do I have to give as argument? – Joetjah Feb 26 '13 at 12:33
  • Never mind, the String-value had to be the value you bind to as defined in your XMAL document. Thank you very much for your time! – Joetjah Feb 26 '13 at 12:37