Bitmap.UriSource 未设置

Bitmap.UriSource is not getting set

这个有效:
Uri 作为参数直接发送给构造函数设置对象 photo.

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

无效:

但是设置 UriSource 属性 会使 UriSource 保持为 null

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

根据MSDN

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

所以你需要这样设置:

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