I tried different methods from existing posts but I am not able to update an image into the Image control. If I execute the code below directly from the view cs, it works fine (so don't pay attention to .Convert method, so the format is ok). However, I am not reaching the image update from another class.
The issue seems to be the OnPropertyChanged event, where the code executes the 'set' of the _displayedImage object properly, but when the 'get' is triggered, the bitmapImage has errors... Why if is the same object?
ViewModel:
//Image displayed
private BitmapImage _displayedImage;
public BitmapImage DisplayedImage
{
get {
return _displayedImage; }
set {
_displayedImage = value;
OnPropertyChanged("DisplayedImage");
}
}
Xaml:
<Image x:Name="ImageViewer" Source="{Binding DisplayedImage}" HorizontalAlignment="Center" VerticalAlignment="Top" Stretch="Fill"/>
Code to update image:
Bitmap bmp= new Bitmap(@"C:\test.jpg");
RunVM.DisplayedImage = Utilities.Instance.Convert(bmp);
Update 1:
When the set is triggered, _displayedImage has the proper content:
After that, when the event is triggered, _displayedImage has errors: