EDIT – After playing around with a bunch of potential solutions (using backgroundworker and separate threads) I’ve found the key issue here is getting the data binding to be ‘interrupted’. Since the progress bar is an animated circle (not a percent complete) it needs to respond to a timer event at consistent intervals to smoothly animate (which is why I can’t data bind one by one and then send a ‘progress’ update back to the ui thread). Does anyone know of away to allow an animation to take place while data binding is going on? Thanks again for everyone’s input!
Original Q –
I bind a large dataset to a WPF list box which can take a long time (more than ten seconds). While the the data is being bound I’d like to display a circular progress bar
I can’t get the progress bar to show while the data binding is occurring, even though I am trying to do the binding in a backgroundworker. I tested it by making the first line of the backgroundworkd’s dowork event a Thread.Sleep(5000) and sure enough the progress bar started spinning for that duration only to freeze while when the binding started.
Is this because both the databinding and the UI updating have to occur on the same thread? Any ideas on how to work around it?
Thanks for your help!!
Use an adorner layer and put your progress indicator in that- that will allow it to overlay the controls on the screen and still respond. Load your data on a back thread and periodically update the control you are displaying your results in (i would also recommend using a virtualizing stack panel as your item panel). This way you can keep the progress indicator in the foreground on a timer for animation and push the incoming data to the results view using the dispatcher and a delgate. We implemented a similar solution for a client (large amounds of data coming in via java web services and spooled to grid- progressive discolsure ;)) and it worked like a champ.