This entry was posted on Thursday, January 26th, 2012 at 3:46 pm and is filed under Tech Stuff. You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.
In WPF when you try to assign a bitmap to a property that’s bound to a UI element from a worker thread you may get the following error:
“Must create DependencySource on same Thread as the DependencyObject”
A simple way around this problem without having to jump through hoops and dispatch to the UI thread is to just freeze the bitmap before assigning it, like this:
var bitmap = new BitmapImage(new Uri(CurrentImageFilePath));
bitmap.Freeze();
this.CurrentImage = bitmap;
bitmap.Freeze();
this.CurrentImage = bitmap;
I hope this helps someone who’s stuck with this annoying error!
