Grrrr!!! This was one of the most frustrating issues I've encountered in WPF. Unlike Winforms where you can always call a .refresh or .invalidate method on a control, no similar functionality exists in WPF. Here's the scenario that caused my problem. I had a splash screen that sets up some things in my applicatoin. The last thing it does is declare a new instance of my main form and then show it. The "new" method of my form takes about 3 seconds to run. Prior to the statement creating the new form we change a status textblock on our splash screen to say "Building User Interface..." Unfortunately, no matter what I did, I could NOT get this visual representation of the text to actually display before the new instance of our main form (which locks the UI and takes 3 seconds) began. I tried playing with the InvalidateVisual, UpdateLayout, InvalidateProperty methods on the textblock, the splash form, etc. withno luck. Basically what I needed was a "DoEvents" type of statement. I ended up doing this withe following code:
Dim datNow As DateTime = Now
While Now.Subtract(datNow).TotalMilliseconds < 100
Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, New ThreadStart(AddressOf doNothing)) ' wait for 100 ms to update textbox...STUPID STUPID STUPID
By allowing it to "chill" for 100 milliseconds it lets the UI render the new text on the textblock control.
I do not like this solution, it is a kludge and there HAS to be a better way to force the visual update of a control. I can't spend any more time on such a menial task. If anyone has any suggestions they'd be much appreciated!