views:

61

answers:

0

Here is a really tricky scenario I have been confronted with. I have a static helper class that contains some dependency properties used as binding sources. My main Window binds to these properties to determine some visual aspects. Recently we have added the ability to measure the progress of long-running operations with a progress bar window. The progress bar window runs on its own thread, and thus has its own Dispatcher. Now what I am trying to do is allow the progress bar window to bind to the same static helper class as the main window, so it can bind to the same visual properties and thus have the same look and feel. This is where my problem arises.

Because the static helper class was created on the main GUI thread, when the progress bar windows (each running on their own thread) attempt to bind to it, the following exception is generated:

"Must create DependencySource on same Thread as the DependencyObject."

How would you work around this? Is there any way the progress bar windows could run on different threads from the main window yet share the same Dispatcher?

EDIT: I have uploaded a sample application (in snippets) to CodeViewer that illustrates how this issue can be reproduced. Here are the links:

MainWindow Code-Behind

MainWindow XAML

ChildWindow Code-Behind

ChildWindow XAML