Bitmap.UriSource is not getting set

810 views Asked by At

This Works:
Sending Uri directly as a parameter to the constructor sets the UriSource of the object photo.

BitmapImage photo = new BitmapImage(new Uri("pack://application:,,,/Images/EmptyImage.jpg"));

enter image description here

Doesn't Work:

But setting the UriSource property keeps the UriSource as null

BitmapImage photo = new BitmapImage();
photo.UriSource = new Uri("pack://application:,,,/Images/EmptyImage.jpg");

enter image description here

1

There are 1 answers

1
Bolu On BEST ANSWER

According to MSDN

BitmapImage.UriSource must be in a BeginInit/EndInit block.

So you need to set it this way:

BitmapImage photo = new BitmapImage();
photo.BeginInit();
photo.UriSource = new Uri("pack://application:,,,/Images/EmptyImage.jpg");
photo.EndInit();