Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. TreeView Children Loading Indicator

TreeView Children Loading Indicator

Scheduled Pinned Locked Moved WPF
helpcsharpwpfcomdesign
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cjb110
    wrote on last edited by
    #1

    I've got a WPF TreeView that is using the structure in Josh Smith's article[^] In my case I've only got one type of object (Unit) that has a self-referencing hierarchy. So I only have one item ViewModel and so only the one HierarchicalDataTemplate. Everything 'works', but there are two usability issues: 1) clicking on the expander can take a while, and there's nothing to indicate to the user that its happening. 2) the expanders appear on items that have no children (I assume due to the DummyChild that gets added. For the 1st issue, I added a INPC property IsLoading to the base item VM TreeViewItemViewModel. Then I've been round and round in circles trying to get this working...at the moment I've got... In my UnitTreeItemViewModel in the LoadChildren override I set IsLoading before and after.

    IsLoading = true;
    //sim a delay
    Thread.Sleep(TimeSpan.FromSeconds(0.75).Milliseconds);

    UI.UIDispatcher.Invoke((ThreadStart)delegate()
    {
    foreach (Unit u in UnitCache.Units.AllUnits.Where(WhereClause))
    base.Children.Add(new UnitTreeItemViewModel(u, this, _uh));
    });

    IsLoading = false;

    Finally I added a simple TextBlock that I make visible based on IsLoading:

    But all this does is show on the child items (after they appear), not the parent:( I've tried changing it to set the Parent's IsLoading, but that didn't seem to work either, the root items don't have Parents for a start... And now I'm stuck... I've created a Pastie of the full code here.

    L 1 Reply Last reply
    0
    • C cjb110

      I've got a WPF TreeView that is using the structure in Josh Smith's article[^] In my case I've only got one type of object (Unit) that has a self-referencing hierarchy. So I only have one item ViewModel and so only the one HierarchicalDataTemplate. Everything 'works', but there are two usability issues: 1) clicking on the expander can take a while, and there's nothing to indicate to the user that its happening. 2) the expanders appear on items that have no children (I assume due to the DummyChild that gets added. For the 1st issue, I added a INPC property IsLoading to the base item VM TreeViewItemViewModel. Then I've been round and round in circles trying to get this working...at the moment I've got... In my UnitTreeItemViewModel in the LoadChildren override I set IsLoading before and after.

      IsLoading = true;
      //sim a delay
      Thread.Sleep(TimeSpan.FromSeconds(0.75).Milliseconds);

      UI.UIDispatcher.Invoke((ThreadStart)delegate()
      {
      foreach (Unit u in UnitCache.Units.AllUnits.Where(WhereClause))
      base.Children.Add(new UnitTreeItemViewModel(u, this, _uh));
      });

      IsLoading = false;

      Finally I added a simple TextBlock that I make visible based on IsLoading:

      But all this does is show on the child items (after they appear), not the parent:( I've tried changing it to set the Parent's IsLoading, but that didn't seem to work either, the root items don't have Parents for a start... And now I'm stuck... I've created a Pastie of the full code here.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You should post your question in the forum at the end of the article, so Josh can help you.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups