Thursday, May 5, 2011

How to detect data binding completed in WPF

When I select an item on my treeview, there is a notable time gap from my viewmodel class being instantiated to the view refreshing and the treeview node being hi-lit.

I need to show a wait cursor during this time - I've tried wrapping the code that instantiates my viewmodel class, but the cursor is back to an arrow a couple of seconds before the whole data binding seems to finish and the node gets hi-lit. Is there some event that tells me when the binding is finished, or when the node is hi-lit ?

This is nothing to do with expanding nodes, simply selecting top-level nodes.

Thanks for any help.

From stackoverflow
  • The Loaded event on the desired TreeView control will happen after all of the bindings have been set up. I think it happens before everything has been drawn though so it might not be exactly what you need.

  • Is there a "hang" when this gap occurs? Maybe you need to put the heavy logic on a separate thread or simply use IsAsync property of the Binding class. You may also want to take a look at Priority Binding. Here is a pretty good article on how to use it.


Post a Comment