Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The ItemContainerGenerator will start generating after the Expanded event, so you can use that to set the Cursor, and set it back once <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.itemcontainergenerator.statuschanged(VS.85).aspx" rel="noreferrer">ItemContainerGenerator.StatusChanged</a> fires to indicate that your children have been populated.</p> <p>Since <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.treeviewitem.expanded(VS.85).aspx" rel="noreferrer">TreeViewItem.Expanded</a> is a routed event, you can just subscribe at some parent level:</p> <pre><code>myTreeView.AddHandler(TreeViewItem.ExpandedEvent, new RoutedEventHandler(TreeViewItemExpanded)); </code></pre> <p>Where TreeViewItemExpanded is defined elsewhere, something like this:</p> <pre><code>private void TreeViewItemExpanded(object sender, RoutedEventArgs e) { // we will only go through with this if our children haven't been populated TreeViewItem sourceItem = e.OriginalSource as TreeViewItem; if ((sourceItem != null) &amp;&amp; (sourceItem.ItemContainerGenerator.Status != GeneratorStatus.ContainersGenerated)) { // create a handler that will check our children and reset the cursor when the ItemContainerGenerator has finished EventHandler itemsGenerated = null; DateTime before = DateTime.Now; itemsGenerated = delegate(object o, EventArgs args) { // if the children are done being generated... if ((o as ItemContainerGenerator).Status == GeneratorStatus.ContainersGenerated) { (o as ItemContainerGenerator).StatusChanged -= itemsGenerated; // we're done, so remove the handler sourceItem.Dispatcher.BeginInvoke(DispatcherPriority.DataBind, (ThreadStart)delegate // asynchronous reset of cursor { myWindow.Cursor = Cursors.Arrow; // reset cursor Debug.WriteLine("Expanded in " + (DateTime.Now - before)); }); } }; sourceItem.ItemContainerGenerator.StatusChanged += itemsGenerated; // add the handler myWindow.Cursor = Cursors.Wait; // wait cursor } e.Handled = true; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload