もちろん、これを解決する策はあり、Invokerを経由すれば可能です。一番簡単な方法は、下記のサンプルソースに示すようにラムダ式を利用することで簡潔に表現できます。
なお、このケースでの注意点はもう1つあります。それは、Imageクラスに描画するためのWritableBitmapもスレッド外から操作できるように、Freezeしておく必要があります。実はここが一番の悩みどころだったりしました。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wbmp = new WriteableBitmap(BitmapFrame.Create(mstr)); //MemoryStreamからWritebleBitmapを生成 | |
wbmp.Freeze(); //Freezeさせるのがポイント | |
newImage.Dispatcher.Invoke( | |
new Action(() => { | |
newImage.Source = wbmp; | |
}) | |
); |
0 件のコメント:
コメントを投稿