(Some were just too complicated to justify trying). When I saw your site, I was very surprised that there is no refresh command in WPF, too. This approach has already saved me a great deal of time!
It also works well for updating progress bars when the percent changes. Looping Method();//This doesnt in the Utilities Class Main Window.
Update (February 26, 2009): A Commenter asked for a VB. Update (January 13, 2010): Apparently geekswithblogs doesn't allow linking non-image files (thus the samples link doesn't work anymore). From my simple test, there are some possibilities as to why it doesn't work for you:1.
I created a Tab Control and have the Tab Items in the XAML; with this scenario, Move Current To does not change the selected tab; if I call Tab Control1. Items (to set it to the second item) then do Tab Control1. If I created the tabitems in code and put them in a Collection View, then Move Current To will also change the Selected Item (tab) and . If you're using Windows 7 (don't know about Vista), I have to change the Dispatcher Priority to Input (or lower) before it'll work. It does work, but only if you have one element in the loop. Also im surprised you need to do any of this at all, since WPF should automatically update the UI when a dependency property is updated (which Content is) To Xcalibur: The post discusses a way to manually force a refresh on a UIElement, given that the busy-code is running on the same thread as the UI Dispatcher thread.
Since we don't want to do anything, I created an empty delegate. When the Dispatcher Priority is set to Render (or lower), the code will then execute all operations that are of that priority or higher. Content to something else, which will result in a render operation. Invoke, the code essentially asks the system to execute all operations that are Render or higher priority, thus the control will then render itself (drawing the new content).
Afterwards, it will then execute the provided delegate (which is our empty method).
The Refresh method is the extension method that takes any UI element and then calls that UIElement's Dispatcher's Invoke method.
The trick is to call the Invoke method with Dispatcher Priority of Render or lower.
The code snippet below also show some C# specific techniques, namely: anonymous delegates and extension methods.
The Looping Method is just the method I use in my Window class to update the label (updating the progress) and then the code does some heavy lifting (Sleep ).
The multithread method is great if you need to keep working inside the GUI while a long-running process does its thing, but where all you want is PROGRESS from a long-running task, this fills the bill like crazy! I've been searching for this for a bit now, and have finally found it! Log Text = "Count of Tasks Fetched and writing to DB\n"; Looping Method(); Any thoughts please..