My custom picture box contains a scrollviewer and an image. A dependecy property Image of type string is used to set the image.
public static DependencyProperty ImageProperty = DependencyProperty.Register(
"Image", typeof(string), typeof(CustomPictureBox), new FrameworkPropertyMetadata("", new PropertyChangedCallback(OnImageChanged)));
private static void OnImageChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
CustomPictureBox cpb = (CustomPictureBox)d;
if (e.Property == ImageProperty)
{
string newvalue = e.NewValue as string;
if (!(string.IsNullOrEmpty(newvalue)))
{
var bmp = new BitmapImage();
bmp.BeginInit();
bmp.UriSource = new Uri(newvalue);
bmp.CacheOption = BitmapCacheOption.OnLoad;
bmp.EndInit();
cpb.imgPicture.Source = bmp;
}
else
cpb.imgPicture.Source = null;
}
}
An image is acquired via frame grabber and stored to a given location with name "camera_image.tif". The Image property is set to this filename. When I start a new image acquisition, I set the Image property via binding to null and the picture box updates to show no image. When the image acquisition is done, I set it to the "camera_image.tif" again. The problem is that the new image never shows up. Instead it is always the first acquired image that is displayed within the picture box. When I check the image file, it contains the new content.
How could I get the picture box to refresh the image?
Regards,
tabina