UI の画像プロパティにバインドされたビューモデルを使用していますが、ビューモデルには ImageSource プロパティが含まれています。次の関数を使用してそのプロパティを設定します
private BitmapImage GetImageFromUri(Uri urisource)
{
if (urisource == null)
return null;
var image = new BitmapImage();
image.BeginInit();
image.UriSource = urisource;
image.EndInit();
image.Freeze(); //commenting this shows the image if the routine is called from the proper thread.
return image;
}
奇妙な理由で、次のコードでは、BitmapImage で Freeze を呼び出すと、メイン ウィンドウに表示されません。例外もクラッシュも発生しません。誰でもこれで私を助けることができますか? イメージ プロパティを非同期で設定しているため、UI スレッド以外のスレッドから GetImageFromUri 呼び出しが行われたと仮定して、作成したイメージを使用できるようにする必要があります。