I want to create a window which contains a progress bar and a label. This window will be shown when certain time consuming tasks are performed (upload/download). It should be a modal window in the sense that it is in the foreground and the UI can take no other input until progress reaches 100%. So, how can I implement such a thing in a generic window?
I can create the window easy enough. I can create an event which broadcasts progress. But, how do I make this one window generic enough to act as a progress for several different tasks. How would I intelligently subscribe to the event (say there are 4 different objects with progress events)?

1 answers
To make the modal window as generic as possible, I imagine you'd want to customize the ProgressBar from the object which opens it and also to execute the long-running task from that object and update the ProgressBar as necessary.
However, as the window is modal, you can't start the task from the object itself because the ProgressBar will not be rendered until ShowDialog() is called and the window will have been closed when ShowDialog() returns.
That being the case, I would suggest that you pass a delegate to the modal window's constructor containing a reference to the method which will execute the task and that the modal window (Window1 say) uses this delegate to execute the task from its ContentRendered event handler.
Here's a little example I managed to get to work. Although I was opening the modal window from the MainWindow class, it could, of course, be any class.
answered one year ago by:
17279