0
votes

The scenario is: In my Window, I have a TreeView; each item of this represents different user-defined types. So I have defined DataTemplate for each type. These DataTemplates are using user-controls and these usercontrols are binded with properties of user-defined types. As simple, TreeView maps a Hierarchical Data Structure of user-defined types.

Now I read from XML and create the Hierarchical structure and assign it to TreeView and it takes a lot of time to load. It already has some default nodes and updates itself for other nodes.

I want to show a wait cursor until it get loaded and available to use for user, but I am not getting any event to notify me this. Is there any such event? What else can I do?

1
Are you sure that it is the application of the data templates that is taking a long time? Seems more likely to be the loading and parsing of the XML and the object creation. You can certainly monitor the status of these operations. - Jay
@Jay The logic I have written is not taking much time, after completeing run of my logic it takes 20-30 seconds to come into view. So, I hope it is treeview loading and data templates applying that is taking time(logic from framework side) - viky
20-30 seconds is an awfully long time; I wonder how many items this hierarchy contains? Would you be able to create the binding and then add items to the hierarchy (in a background thread, even), or does the entire graph need to be created before anything is displayed? - Jay
@Jay My tree can contain 500-600 elements(it can contain even more than this), Further my DataTemplates use usercontrols in them, I don't know how to Create Binding and add items in Hierarchy in Background thread, can you provide me some sample? - viky

1 Answers

0
votes

Try the LayoutUpdated event, as in...

Mouse.OverrideCursor = Cursors.Wait;
treeView.LayoutUpdated += treeView_LayoutUpdated;

void treeView_LayoutUpdated( object sender, EventArgs e )
{
    Mouse.OverrideCursor = null;
    treeView.LayoutUpdated -= treeView_LayoutUpdated;
}